/// <summary> /// Registers a type in the container only if that type was not already registered. /// </summary> /// <param name="fromType">The registration type.</param> /// <param name="toType">The type implementing the registration type.</param> /// <param name="scope">Scope of the registered type.</param> /// <returns> /// The <see cref="IContainerAdapter"/> with the newly registered element. /// </returns> public IContainerAdapter RegisterTypeIfMissing(Type fromType, Type toType, ContainerRegistrationScope scope) { if (Container.IsRegistered(fromType)) { ContainerAdapterExtensions.TypeMappingAlreadyRegistered(Logger, fromType); } else { RegisterType(fromType, toType, scope); } return(this); }
/// <summary> /// Registers a type in the container. /// </summary> /// <param name="fromType">The registration type.</param> /// <param name="toType">The type implementing the registration type.</param> /// <param name="scope">Scope of the registered type.</param> /// <returns> /// The <see cref="IContainerAdapter"/> with the newly registered element. /// </returns> public IContainerAdapter RegisterType(Type fromType, Type toType, ContainerRegistrationScope scope) { var builder = new ContainerBuilder(); { if (scope.IsSingleton()) { builder.RegisterType(toType).As(fromType).SingleInstance(); } else { builder.RegisterType(toType).As(fromType).InstancePerDependency(); } } builder.Update(Container); return(this); }
public IContainerAdapter RegisterType <TFrom, TTo>(ContainerRegistrationScope scope) where TTo : TFrom { var builder = new ContainerBuilder(); { if (scope.IsSingleton()) { builder.RegisterType <TTo>().As <TFrom>().SingleInstance(); } else { builder.RegisterType <TTo>().As <TFrom>().InstancePerDependency(); } } builder.Update(Container); return(this); }
public IContainerAdapter RegisterTypeIfMissing <TFrom, TTo>(ContainerRegistrationScope scope) where TTo : TFrom { if (Container.IsRegistered <TFrom>()) { Logger.Log( string.Format( CultureInfo.InvariantCulture, "Type is already registered: {0}", typeof(TFrom).Name), Category.Warn, Priority.Medium); ContainerAdapterExtensions.TypeMappingAlreadyRegistered <TFrom>(Logger); } else { RegisterType <TFrom, TTo>(scope); } return(this); }
public static bool IsInstance(this ContainerRegistrationScope scope) { return(scope == ContainerRegistrationScope.Instance); }
public static bool IsSingleton(this ContainerRegistrationScope scope) { return(scope == ContainerRegistrationScope.Singleton); }