DI with Unity
DependencyInjector.cs
public static class DependencyInjector
{
private static readonly UnityContainer UnityContainer = new UnityContainer();
public static void Register<I, T>() where T : I
{
UnityContainer.RegisterType<I, T>(new ContainerControlledLifetimeManager());
}
public static void InjectStub<I>(I instance)
{
UnityContainer.RegisterInstance(instance, new ContainerControlledLifetimeManager());
}
public static T Retrieve<T>()
{
return UnityContainer.Resolve<T>();
}
}
Bootstrapper.cs
public static class Bootstrapper
{
public static void Init()
{
DependencyInjector.Register<IConfigurationRespository, ConfigurationRespository>();
DependencyInjector.Register<IRestClient, RestClient>();
DependencyInjector.Register<ISerializer, JsonSerializer>();
DependencyInjector.Register<IUrlManager, UrlManager>();
DependencyInjector.Register<ILinkRepository, LinkRespositoryJson>();
DependencyInjector.Register<IProviderRespository,ProviderJson>();
DependencyInjector.Register<ILinkValidation,LinkValidation>();
DependencyInjector.Register<ILinkInformationUpdater,LinkInformationUpdater>();
}
}