Where is Microsoft.Practices.Unity package?
I had to change using Microsoft.Practices.unity; to using Unity; I think because of an update in Unity with NuGet
I had to change using Microsoft.Practices.unity; to using Unity; I think because of an update in Unity with NuGet
The overload with the InjectionMember array is used, when you do not provide a configuration file that Unity tells how to create an instance of the given type or if you want to create an instance by another way than defined in the configuration file. The overloads are used, when you want to configure an … Read more
I know that an answer has been chosen, however I think a part of Unity is being overlooked. Since this was a specific Unity question I thought I point out the UnityContainerExtension base class that implements the IUnityContainerExtensionConfigurator. This is there for API library to extend to make it easy for the entry-point application who … Read more
First, you need a proper lifetime manager the ContainerControlledLifetimeManager is for singletons. For custom initialization, you could probably use InjectionFactory This lets you write any code which initializes the entity. Edit1: this should help public static void Register(IUnityContainer container) { container .RegisterType<IEmail, Email>( new ContainerControlledLifetimeManager(), new InjectionFactory(c => new Email( “To Name”, “[email protected]”))); } and … Read more
Specifically addressed in the PDC 2008 2nd Keynote by Scott Guthrie, MEF has a lot more to do with things like extending Visual Studio 2008 and other applications, without having to use all the COM and older technologies… A very good demonstration of extending the text edition in VS2008 was shown among other things. Start … Read more
One way is to have RepositoryFactory implement IRepositoryFactory, then register that. Resolved types can get a factory, then call its CreateAuthoringRepository method. You could create an overload called CreateAuthoringRepositoryForCurrentIdentity if desired, or register an IIdentity dependency of the factory with Unity. I’d probably just inject a factory and leave the CreateAuthoringRepository method as you have … Read more
I was running in to the same issue using Unity with WebApi and OWIN/Katana. The solution for me was to use the UnityDependencyResolver defined in the Unity.WebApi Nuget package instead of my own custom implementation (like @Omar Alani above) Install-Package Unity.WebAPI Note that the package will try and add a file named UnityConfig.cs in App_Start … Read more
The method RegisterInstance of the UnityContainer will always override the last registration entry if you do not distinguish them by name. So if you call container.RegisterInstance<IHardware>(new HardwareB()); you will override the registration for the interface IHardware and will retreive HardwareB on the next resolving attempt
If you want to build an MVVM application (which you probably do for various advantages), then you want an MVVM framework. I would recommend Caliburn.Micro, as it is straightforward to implement following the examples on the Caliburn.Micro documentation page. It also has a very compelling convention over configuration mechanism, and uses an Actions system to … Read more
Unit tests should not use the container at all. Dependency Injection (DI) comes in two phases: Use DI patterns to inject dependencies into consumers. You don’t need a container to do that. At the application’s Composition Root, use a DI Container (or Poor Man’s DI) to wire all components together. How not to use any … Read more