You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The main issue is that when you register a factory alongside a default implementation, resolving either always results in the default implementation.
Version Information
LightInject 5.0.3.0
Platform
.NET Framework 4.7.2
An example that shows the issue.
varcontainer=new ServiceContainer();
container.Register<IPushNotificationSender,FirebasePushNotificationsSender>(new PerContainerLifetime());
container.Register<IPushNotificationSender,NotificationsWebPushSender>(DeviceMessageTypes.Chrome.ToString(),new PerContainerLifetime());
container.Register<IPushNotificationSender,NotificationsWebPushSender>(DeviceMessageTypes.FireFox.ToString(),new PerContainerLifetime());
container.Register<IPushNotificationSender,NotificationsGcmPushSender>(DeviceMessageTypes.GCM.ToString(),new PerContainerLifetime());
container.Register<IPushNotificationSender,NotificationsApnPushSender>(DeviceMessageTypes.APN.ToString(),new PerContainerLifetime());
container.Register<DeviceMessageTypes,IPushNotificationSender>((factory,value)=> factory.GetInstance<IPushNotificationSender>(value.ToString()));varfactory= container.GetInstance<Func<DeviceMessageTypes,IPushNotificationSender>>();varmainImpl= container.GetInstance<IPushNotificationSender>();varfactoryImpl= factory(DeviceMessageTypes.APN);if(factoryImpl.GetType().Name == mainImpl.GetType().Name){// These shouldn't be the same... // The factory should resolve to the factory function in the registration.
Console.WriteLine("Expected factory to resolve to different type.");
Console.WriteLine($"Expected Type: {typeof(NotificationsApnPushSender).Name}");
Console.WriteLine($"Resolved Type: {factoryImpl.GetType().Name}");}
The text was updated successfully, but these errors were encountered:
The main issue is that when you register a factory alongside a default implementation, resolving either always results in the default implementation.
Version Information
LightInject 5.0.3.0
Platform
.NET Framework 4.7.2
An example that shows the issue.
The text was updated successfully, but these errors were encountered: