/// <summary> /// Assigns an existing instance as the component for this registration. /// </summary> /// <param name = "instance">The component instance.</param> /// <returns></returns> public ComponentRegistration <TService> Instance(TService instance) { if (instance == null) { throw new ArgumentNullException("instance"); } return(ImplementedBy(instance.GetType()) .Activator <ExternalInstanceActivator>() .ExtendedProperties(Property.ForKey("instance").Eq(instance))); }
public ComponentRegistration <TService> ActAs(params object[] actors) { foreach (var actor in actors) { if (actor != null) { DependsOn(Property.ForKey(Guid.NewGuid().ToString()).Eq(actor)); } } return(this); }
/// <summary> /// Sets the concrete type that implements the service to <paramref name = "type" />. /// <para /> /// If not set, the class service type or first registered interface will be used as the implementation for this component. /// </summary> /// <param name = "type">The type that is the implementation for the service.</param> /// <param name = "genericImplementationMatchingStrategy">Provides ability to close open generic service. Ignored when registering closed or non-generic component.</param> /// <returns></returns> public ComponentRegistration <TService> ImplementedBy(Type type, IGenericImplementationMatchingStrategy genericImplementationMatchingStrategy) { if (implementation != null && implementation != typeof(LateBoundComponent)) { var message = String.Format("This component has already been assigned implementation {0}", implementation.FullName); throw new ComponentRegistrationException(message); } implementation = type; if (genericImplementationMatchingStrategy == null) { return(this); } return(ExtendedProperties(Property.ForKey(ComponentModel.GenericImplementationMatchingStrategy).Eq(genericImplementationMatchingStrategy))); }
/// <summary> /// Uses a factory method to instantiate the component. /// </summary> /// <typeparam name = "TImpl">Implementation type</typeparam> /// <param name = "factoryMethod">Factory method</param> /// <param name = "managedExternally">When set to <c>true</c> container will not assume ownership of this component, will not track it not apply and lifecycle concerns to it.</param> /// <returns></returns> public ComponentRegistration <TService> UsingFactoryMethod <TImpl>(Func <IKernel, ComponentModel, CreationContext, TImpl> factoryMethod, bool managedExternally = false) where TImpl : TService { Activator <FactoryMethodActivator <TImpl> >() .ExtendedProperties(Property.ForKey("factoryMethodDelegate").Eq(factoryMethod)); if (managedExternally) { ExtendedProperties(Property.ForKey("factory.managedExternally").Eq(managedExternally)); } if (implementation == null && (potentialServices.First().IsClass == false || potentialServices.First().IsSealed == false)) { implementation = typeof(LateBoundComponent); } return(this); }
/// <summary> /// Specifies that component registered with <paramref name = "componentName" /> should be used to satisfy dependencies matched by <paramref /// name = "dependencyType" /> /// </summary> public static ServiceOverride OnComponent(Type dependencyType, string componentName) { return(Property.ForKey(dependencyType).Is(componentName)); }
/// <summary> /// Specifies that value <paramref name = "value" /> should be used to satisfy dependencies matched by <typeparamref /// name = "TDependencyType" /> /// </summary> public static Property OnValue <TDependencyType>(object value) { return(Property.ForKey <TDependencyType>().Eq(value)); }
/// <summary> /// Specifies that value <paramref name = "value" /> should be used to satisfy dependencies matched by <paramref /// name = "dependencyType" /> /// </summary> public static Property OnValue(Type dependencyType, object value) { return(Property.ForKey(dependencyType).Eq(value)); }
/// <summary> /// Specifies that value <paramref name = "value" /> should be used to satisfy dependencies matched by <paramref /// name = "dependencyName" /> /// </summary> public static Property OnValue(string dependencyName, object value) { return(Property.ForKey(dependencyName).Eq(value)); }
/// <summary> /// Specifies that component registered with <typeparamref name = "TComponentType" /> should be used to satisfy dependencies matched by <typeparamref /// name = "TDependencyType" /> /// </summary> public static ServiceOverride OnComponent <TDependencyType, TComponentType>() { return(Property.ForKey <TDependencyType>().Is <TComponentType>()); }
/// <summary> /// Specifies that component registered with <paramref name = "componentType" /> should be used to satisfy dependencies matched by <paramref /// name = "dependencyName" /> /// </summary> public static ServiceOverride OnComponent(string dependencyName, Type componentType) { return(Property.ForKey(dependencyName).Is(componentType)); }
public static Property OnResource(string dependencyName, ResourceManager resourceManager, string resourceName) { return(Property.ForKey(dependencyName).Eq(resourceManager.GetObject(resourceName))); }