using TheXamlGuy.Framework.Core; namespace TheXamlGuy.Framework.Camera; public class CameraFactory : ICameraFactory { private readonly Dictionary 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(); } else { context = factory.Create(); } cache.Add(configuration, context); return context; } }