public void Register <TService, TImplementor>(IocLifecycle lifecycle) where TService : class where TImplementor : class, TService { var mappedLifecycle = MapLifecycle(lifecycle); _container.AddService(typeof(TService), typeof(TImplementor), mappedLifecycle); }
private static LifecycleType MapLifecycle(IocLifecycle lifecycle) { switch (lifecycle) { case IocLifecycle.PerRequest: return(LifecycleType.OncePerRequest); case IocLifecycle.PerThread: return(LifecycleType.OncePerThread); } return(LifecycleType.Singleton); }
public void RegisterMultiple <TBaseTypeToRegister, TTypeToReturn>(IocLifecycle lifecycle) where TBaseTypeToRegister : class where TTypeToReturn : class, TBaseTypeToRegister { if (lifecycle == IocLifecycle.PerRequest) { this.tinyIoCContainer.RegisterMultiple <TBaseTypeToRegister>(new[] { typeof(TTypeToReturn) }); } else { this.tinyIoCContainer.RegisterMultiple <TBaseTypeToRegister>(new[] { typeof(TTypeToReturn) }).AsSingleton(); } }
public void Register <TBaseTypeToRegister, TTypeToReturn>(IocLifecycle lifecycle) where TTypeToReturn : class, TBaseTypeToRegister where TBaseTypeToRegister : class { if (lifecycle == IocLifecycle.PerRequest) { this.tinyIoCContainer.Register <TBaseTypeToRegister, TTypeToReturn>(); } else { this.tinyIoCContainer.Register <TBaseTypeToRegister, TTypeToReturn>().AsSingleton(); } }
public void Register <TService, TImplementor>(IocLifecycle lifecycle) where TService : class where TImplementor : class, TService { switch (lifecycle) { case IocLifecycle.PerRequest: serviceCollection.AddTransient <TService, TImplementor>(); break; case IocLifecycle.PerThread: throw new NotImplementedException(); case IocLifecycle.Singleton: serviceCollection.AddSingleton <TService, TImplementor>(); break; default: throw new NotImplementedException(); } }