Exemplo n.º 1
0
 /// <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)));
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        /// <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)));
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 /// <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));
 }
Exemplo n.º 6
0
 /// <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));
 }
Exemplo n.º 7
0
 /// <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));
 }
Exemplo n.º 8
0
 /// <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));
 }
Exemplo n.º 9
0
 /// <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>());
 }
Exemplo n.º 10
0
 /// <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));
 }
Exemplo n.º 11
0
 public static Property OnResource(string dependencyName, ResourceManager resourceManager, string resourceName)
 {
     return(Property.ForKey(dependencyName).Eq(resourceManager.GetObject(resourceName)));
 }