/// <summary> /// Register an instance as singleton (if no other <see cref="Lifetime{T}"/> style specified) and /// use its concrete type, the base type from which it derives, or one of the interfaces it implements as /// the retrieval key. /// </summary> /// <typeparam name="TConcrete">The concrete type of the instance, the base type from which the instance /// derives, or one of the interfaces the instance implements.</typeparam> /// <param name="registrar">The registrar.</param> /// <param name="instance">The instance.</param> /// <returns>The method configurator</returns> public static ICommonConfigurationApi Register <TConcrete>(this IObjectRegistrar registrar, TConcrete instance) { Requires.NotNull(registrar, "registrar"); Requires.NotNull(instance, "instance"); Requires.IsPublicAccessibleType(typeof(TConcrete), "TConcrete"); return(DoRegister <TConcrete, TConcrete>(registrar, instance)); }
static ICommonConfigurationApi DoRegister <TContract, TConcrete>(this IObjectRegistrar registrar, TConcrete instance) where TConcrete : TContract { var configurator = new InstanceConfigurationApi <TContract>(); configurator.CreateRegistrationProvider(registrar.Kernel, instance); var provider = configurator.GetRegistrationProvider(); registrar.Register(provider); return(configurator); }
public void Register(IObjectRegistrar registrar) { foreach (var binding in _bindings) { registrar.Register(binding.ControllerType) .WithPropertyAutowired("Coordinator") // Inject the Coordinator .Matadata(binding.PairName); // set the metadata registrar.Register(binding.ViewContractType, binding.ViewConcreteType) .WhenMetadataIs(binding.PairName); // can only be injected into Controller with the same metadata } _bindings = null; }
/// <summary> /// Register a service using the provided <paramref name="factory"/> and specify a implementation type, which might be the /// concrete type of the returned object instance the <paramref name="factory"/> created, the base type from which it /// derives, or one of the interface it implements, as the retrieval key. /// </summary> /// <typeparam name="TContract">The concrete type of the returned object instance which the <paramref name="factory"/> /// created, the base type from which it derives, or one of the interface it implements.</typeparam> /// <param name="registrar">The registrar.</param> /// <param name="factory">The factory.</param> /// <returns>The method configurator</returns> public static ICommonConfigurationApi Register <TContract>(this IObjectRegistrar registrar, Func <IResolutionContext, TContract> factory) { Requires.NotNull(registrar, "registrar"); Requires.NotNull(factory, "factory"); Requires.IsPublicAccessibleType(typeof(TContract), "TContract"); var configurator = new FuncConfigurationApi <TContract>(); configurator.CreateRegistrationProvider(registrar.Kernel, factory, typeof(TContract)); var provider = configurator.GetRegistrationProvider(); registrar.Register(provider); return(configurator); }
static ITypeConfigurationApi RegisterWithType(this IObjectRegistrar registrar, Type contractType, Type concreteType) { Requires.NotNull(contractType, "contractType"); Requires.NotNull(concreteType, "concreteType"); Requires.IsPublicAccessibleType(contractType, "contractType"); Requires.IsPublicAccessibleType(concreteType, "concreteType"); Requires.IsNotOpenGenericType(concreteType, "concreteType"); Requires.IsConcreteType(concreteType, "concreteType"); Requires.IsAutowirableType(contractType, "contractType"); Requires.IsAssignableFrom(contractType, concreteType); var configurator = new ReflectionOrEmitConfigurationApi(); configurator.CreateRegistrationProvider(registrar.Kernel, contractType, concreteType); var provider = configurator.GetRegistrationProvider(); registrar.Register(provider); return(configurator); }
/// <summary> /// Unregisters multiple components from the container using the <see cref="IObjectRegistration"/>s associated with them, /// so that it can't be used to serve the later requests. The components will be unregistered anyway, whether they are /// depended on by any other components or not. /// But if there are components that depends on them, then the dependencies of those components will be updated /// to allow to them rebind to other components at the next time they are requested. /// </summary> /// <param name="registrar">The registrar.</param> /// <param name="registrations">The registrations.</param> /// <returns></returns> public static void Unregister(this IObjectRegistrar registrar, params IObjectRegistration[] registrations) { Requires.NotNull(registrar, "registrar"); registrar.Kernel.Unregister(registrations); }
/// <summary> /// Unregisters multiple components from the container using the <see cref="IObjectRegistration"/>s associated with them, /// so that it can't be used to serve the later requests. The components will be unregistered anyway, whether they are /// depended on by any other components or not. /// But if there are components that depends on them, then the dependencies of those components will be updated /// to allow to them rebind to other components at the next time they are requested. /// </summary> /// <param name="registrar">The registrar.</param> /// <param name="registrations">The registrations.</param> /// <returns></returns> public static void Unregister(this IObjectRegistrar registrar, IEnumerable <IObjectRegistration> registrations) { Requires.NotNull(registrar, "registrar"); registrar.Kernel.Unregister(registrations); }
public static ITypeConfigurationApi Register <TContract>(this IObjectRegistrar registrar, Type concreteType) where TContract : class { return(RegisterWithTypeGeneric <TContract>(registrar, concreteType)); }
/// <summary> /// Register a service using the provided <typeparamref name="TConcrete"/> and specify the /// <typeparamref name="TContract"/>, which might be a base type from which the /// <typeparamref name="TConcrete"/> derives or one of the interfaces it implements, as the /// retrieval key. /// </summary> /// <typeparam name="TContract">The base type from which the <typeparamref name="TConcrete"/> /// derives, or one of the interface it implements.</typeparam> /// <typeparam name="TConcrete">The concrete type that will be used to create a object instance.</typeparam> /// <param name="registrar">The registrar.</param> /// <returns> /// The method configurator /// </returns> public static ITypeConfigurationApi Register <TContract, TConcrete>(this IObjectRegistrar registrar) where TContract : class where TConcrete : TContract { return(RegisterWithTypeGeneric <TContract>(registrar, typeof(TConcrete))); }
/// <summary> /// Register a service using the provided <paramref name="concreteType"/> and specify the /// <paramref name="contractType"/>, which might be a base type from which the /// <paramref name="concreteType"/> derives or one of the interfaces it implements, as the /// retrieval key. /// </summary> /// <param name="registrar">The registrar.</param> /// <param name="contractType">The base type from which the <paramref name="concreteType"/> derives, or one of the /// interface it implements.</param> /// <param name="concreteType">The concrete type that will be used to create a object instance.</param> /// <returns> /// The method configurator /// </returns> public static ITypeConfigurationApi Register(this IObjectRegistrar registrar, Type contractType, Type concreteType) { return(RegisterWithType(registrar, contractType, concreteType)); }