/// <summary> /// Register type /// </summary> /// <typeparam name="TAbstractType"></typeparam> /// <typeparam name="TConcreteType"></typeparam> /// <param name="lifeCycleType"></param> public void Register <TAbstractType, TConcreteType>(LifeCycleType lifeCycleType = LifeCycleType.Transient) { var typeName = typeof(TAbstractType).ToString(); try { // remove registration if (registrations.ContainsKey(typeName)) { UnRegister <TAbstractType>(); } // register registrations.Add(typeName, new Registration { AbstractType = typeof(TAbstractType), ConcreteType = typeof(TConcreteType), LifeCycleType = lifeCycleType }); } catch (Exception ex) { throw new Exception(string.Format("There was an error registering '{0}'.", typeName), ex); } }
public void Register <TInterface, TClass>(LifeCycleType lifeCycle = LifeCycleType.Transient) { if (!_bindings.ContainsKey(typeof(TInterface))) { _bindings.Add(typeof(TInterface), new Binding { LifeCycle = lifeCycle, MyType = typeof(TClass) }); } }
public void Register(Type service, Type implementationType, LifeCycleType lifestyle) { switch (lifestyle) { case LifeCycleType.Singleton: _container.Register(service, implementationType, Lifestyle.Singleton); break; case LifeCycleType.Scoped: _container.Register(service, implementationType, Lifestyle.Scoped); break; case LifeCycleType.Transient: _container.Register(service, implementationType, Lifestyle.Transient); break; } }
public void Register(Type service, Assembly assemblies, LifeCycleType lifestyle) { switch (lifestyle) { case LifeCycleType.Singleton: _container.Register(service, assemblies, Lifestyle.Singleton); break; case LifeCycleType.Scoped: _container.Register(service, assemblies, Lifestyle.Scoped); break; case LifeCycleType.Transient: _container.Register(service, assemblies, Lifestyle.Transient); break; } }
public void Register <TService, TImplementation>(LifeCycleType lifestyle) { switch (lifestyle) { case LifeCycleType.Singleton: _container.Register(typeof(TService), typeof(TImplementation), Lifestyle.Singleton); break; case LifeCycleType.Scoped: _container.Register(typeof(TService), typeof(TImplementation), Lifestyle.Scoped); break; case LifeCycleType.Transient: _container.Register(typeof(TService), typeof(TImplementation), Lifestyle.Transient); break; } }
public void Register <TService>(Func <object> instanceCreator, LifeCycleType lifestyle) { switch (lifestyle) { case LifeCycleType.Singleton: _container.Register(typeof(TService), instanceCreator, Lifestyle.Singleton); break; case LifeCycleType.Scoped: _container.Register(typeof(TService), instanceCreator, Lifestyle.Scoped); break; case LifeCycleType.Transient: _container.Register(typeof(TService), instanceCreator, Lifestyle.Singleton); break; } }
public void Register <MappedEntityType, ConcreteType>(LifeCycleType lifeCycleType = LifeCycleType.Transiet) { mappedEntities.Add(typeof(MappedEntityType), new MappedEntity(typeof(MappedEntityType), typeof(ConcreteType), lifeCycleType)); }
public MappedEntity(Type mappedType, Type concreteType, LifeCycleType lifeCycle) { MappedType = mappedType; ConcreteType = concreteType; LifeCycle = lifeCycle; }
private Mock<IServiceContainer> GetContainerMock(LifeCycleType lifeCycleType, Func<Type, bool> shouldRegister) { var containerMock = new Mock<IServiceContainer>(); var assemblyScanner = new AssemblyScanner(); assemblyScanner.Scan(typeof(IFoo).Assembly, containerMock.Object, lifeCycleType, shouldRegister); return containerMock; }