IoC in class library. Where to bootstrap

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

Unity Singleton Code

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

How to create objects using a static factory method?

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

Web Api Start up Exceptions with IDependencyResolver implementation

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

Unity: Replace registered type with another type at runtime

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

MVVM, Unity, Prism, MEF, Caliburn – What should I use?

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

Proper way to Mock repository objects for unit tests using Moq and Unity

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

techhipbettruvabetnorabahisbahis forumueduseduedueduedueduedueduseduedus