Microsoft Unity - 'Microsoft.Practices.Unity.InjectedMembers' is obsolete: 'Use the IUnityContainer.RegisterType method instead of this interface'
While preparing a release I was cleaning up some build warnings that sneaked into the code.
One of the warnings I got was the following regarding Unity, Microsoft’s IoC container:
Warning 11 'Microsoft.Practices.Unity.InjectedMembers' is obsolete: 'Use the IUnityContainer.RegisterType method instead of this interface' C:\Projects\Services\ServicesConfiguration.cs 136 38 Services
The warning was coming from the following code:
var container=new UnityContainer(); | |
container.Configure<InjectedMembers>() | |
.ConfigureInjectionFor | |
( | |
typeof(ServiceAgentConfiguration<>), | |
new InjectionConstructor | |
( | |
typeof(IBindingFactory<>), | |
typeof(IServiceAddressConvention<>), | |
container.Resolve<ISettings>().UseConventionsToConfigureServices | |
) | |
); | |
Using this code I’m configuring the constructor parameters when a ServiceAgentConfiguration class is resolved from the IoC container. I was doing this through the InjectedMembers object from Unity. However this class is obsolete, so I had to update my code to the following:
var container=new UnityContainer(); | |
container.RegisterType(typeof(IServiceAgentConfiguration<>), typeof(ServiceAgentConfiguration<>), new InjectionConstructor | |
( | |
typeof(IBindingFactory<>), | |
typeof(IServiceAddressConvention<>), | |
this.Container.Resolve<ISOFASettings>().UseConventionsToConfigureServices | |
)); |