public void Register <T1, T2>(LifeTimeOptions lifeTimeOption) { if (iocMap.ContainsKey(typeof(T1))) { throw new Exception(string.Format("Type {0} already registered.", typeof(T1).FullName)); } ResolvedTypeWithLifeTimeOptions targetType = new ResolvedTypeWithLifeTimeOptions(typeof(T2), lifeTimeOption); iocMap.Add(typeof(T1), targetType); }
public void Register <TTypeToResolve, TResolvedType>(LifeTimeOptions options) { if (_iocMap.ContainsKey(typeof(TTypeToResolve))) { throw new Exception($"Type {typeof(TTypeToResolve).FullName} already registered."); } var targetType = new ResolvedTypeWithLifeTimeOptions(typeof(TResolvedType), options); _iocMap.Add(typeof(TTypeToResolve), targetType); }
/// <summary> /// Add service bind by implemented interface /// </summary> /// <param name="services">Service collection</param> /// <param name="type">Binding type</param> /// <param name="options">Life time binding option</param> /// <param name="propertyAutoWired">Use option auto wired property</param> internal void Add(IServiceCollection services, Type type, LifeTimeOptions options, bool propertyAutoWired) { var implementedInterface = type.GetInterfaces() .FirstOrDefault(); _addBindingWrapper.Add(services, implementedInterface, type, options, propertyAutoWired); }
/// <summary> /// Add bind service with options /// </summary> /// <param name="services">Service collection</param> /// <param name="type">Binding type</param> /// <param name="implementType">Type which implemented</param> /// <param name="options">Life time binding option</param> /// <param name="propsAutoWired">Use option auto wired property</param> internal void Add(IServiceCollection services, Type type, Type implementType, LifeTimeOptions options, bool propsAutoWired) { switch (options) { case LifeTimeOptions.Scoped: _addScopedWrapper.Add(services, type, implementType, propsAutoWired); break; case LifeTimeOptions.Singleton: _addSingletonWrapper.Add(services, type, implementType, propsAutoWired); break; default: _addTransientWrapper.Add(services, type, implementType, propsAutoWired); break; } }
/// <summary> /// Initializes a new instance of the <see cref="ResolvedTypeWithLifeTimeOptions"/> class. /// </summary> /// <param name="resolvedType">The <see cref="Type"/> to be resolved.</param> /// <param name="lifeTimeOptions">The <see cref="LifeTimeOptions"/> of the type to be resolved.</param> public ResolvedTypeWithLifeTimeOptions(Type resolvedType, LifeTimeOptions lifeTimeOptions) { this.ResolvedType = resolvedType; this.LifeTimeOption = lifeTimeOptions; this.InstanceValue = null; }
public ResolvedTypeWithLifeTimeOptions(Type resolvedType, LifeTimeOptions lifeTimeOption) { ResolvedType = resolvedType; LifeTimeOption = lifeTimeOption; InstanceValue = null; }
public ResolvedTypeWithLifeTimeOptions(Type resolvedType, LifeTimeOptions lifeTimeOption) { ResolvedType = resolvedType; LifeTimeOption = lifeTimeOption; InstanceValue = null; }