Files
2022-11-01 15:26:08 +00:00

35 lines
861 B
C#

using TheXamlGuy.Framework.Core;
namespace TheXamlGuy.Framework.Camera;
public class CameraFactory : ICameraFactory
{
private readonly Dictionary<INamedCameraConfiguration, ICameraContext> cache = new();
private readonly IServiceFactory factory;
public CameraFactory(IServiceFactory factory)
{
this.factory = factory;
}
public ICameraContext Create(INamedCameraConfiguration configuration)
{
if (cache.TryGetValue(configuration, out ICameraContext? context))
{
return context;
}
if (configuration is IRemoteCameraConfiguration)
{
context = factory.Create<RemoteCameraContext>();
}
else
{
context = factory.Create<CameraContext>();
}
cache.Add(configuration, context);
return context;
}
}