/// <summary>
    /// Registers the given type as a Rebus message handler
    /// </summary>
    public static void RegisterHandler <THandler>(this ContainerBuilder builder, PropertyWiringOptions propertyWiringOptions = PropertyWiringOptions.None) where THandler : IHandleMessages
    {
        if (builder == null)
        {
            throw new ArgumentNullException(nameof(builder));
        }

        var implementedHandlerTypes = GetImplementedHandlerInterfaces(typeof(THandler)).ToArray();

        builder.RegisterType(typeof(THandler)).As(implementedHandlerTypes)
        .InstancePerDependency()
        .PropertiesAutowired(propertyWiringOptions);
    }
Exemple #2
0
        PropertiesAutowired <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] TLimit, TActivatorData, TRegistrationStyle>(
            this IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> registration, PropertyWiringOptions wiringFlags = PropertyWiringOptions.None)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            var preserveSetValues         = (int)(wiringFlags & PropertyWiringOptions.PreserveSetValues) != 0;
            var allowCircularDependencies = (int)(wiringFlags & PropertyWiringOptions.AllowCircularDependencies) != 0;

            return(registration.PropertiesAutowired(new DefaultPropertySelector(preserveSetValues), allowCircularDependencies));
        }
        /// <summary>
        /// Configure the component so that any properties whose types are registered in the
        /// container will be wired to instances of the appropriate service.
        /// </summary>
        /// <param name="wiringFlags">Set wiring options such as circular dependency wiring support.</param>
        /// <returns>A registration builder allowing further configuration of the component.</returns>
        public IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> PropertiesAutowired(PropertyWiringOptions wiringFlags)
        {
            var allowCircularDependencies = 0 != (int)(wiringFlags & PropertyWiringOptions.AllowCircularDependencies);
            var preserveSetValues         = 0 != (int)(wiringFlags & PropertyWiringOptions.PreserveSetValues);

            if (allowCircularDependencies)
            {
                RegistrationData.ActivatedHandlers.Add((s, e) => AutowiringPropertyInjector.InjectProperties(e.Context, e.Instance, !preserveSetValues));
            }
            else
            {
                RegistrationData.InjectPropertiesHandlers.Add((s, e) => AutowiringPropertyInjector.InjectProperties(e.Context, e.Instance, !preserveSetValues));
            }

            return(this);
        }
        public static IRegistrationBuilder <TLimit, TReflectionActivatorData, TRegistrationStyle> ExtendedPropertiesAutowired <TLimit, TReflectionActivatorData, TRegistrationStyle>(this IRegistrationBuilder <TLimit, TReflectionActivatorData, TRegistrationStyle> registrationBuilder,
                                                                                                                                                                                     PropertyWiringOptions wiringFlags = PropertyWiringOptions.None)
        {
            var allowCircularDependencies = 0 != (int)(wiringFlags & PropertyWiringOptions.AllowCircularDependencies);
            var preserveSetValues         = 0 != (int)(wiringFlags & PropertyWiringOptions.PreserveSetValues);

            if (allowCircularDependencies)
            {
                registrationBuilder.RegistrationData.ActivatedHandlers.Add((s, e) => ExtendedAutowiringPropertyInjector.InjectProperties(e.Context, e.Instance, !preserveSetValues));
            }
            else
            {
                registrationBuilder.RegistrationData.ActivatedHandlers.Add((s, e) => ExtendedAutowiringPropertyInjector.InjectProperties(e.Context, e.Instance, !preserveSetValues));
            }

            return(registrationBuilder);
        }
 /// <summary>
 /// Registers all Rebus message handler types found in the assembly of <typeparamref name="T"/> under the namespace that type lives
 /// under. So all types within the same namespace will get mapped as handlers, but not types under other namespaces. This allows
 /// you to separate messages for specific queues by namespace and register them all in one go.
 /// </summary>
 public static void RegisterHandlersFromAssemblyNamespaceOf <T>(this ContainerBuilder builder, PropertyWiringOptions propertyWiringOptions = PropertyWiringOptions.None)
 {
     RegisterHandlersFromAssemblyNamespaceOf(builder, typeof(T), propertyWiringOptions);
 }
    /// <summary>
    /// Registers all Rebus message handler types found in the assembly of <paramref name="handlerType"/>
    /// </summary>
    public static void RegisterHandlersFromAssemblyOf(this ContainerBuilder builder, Type handlerType, PropertyWiringOptions propertyWiringOptions = PropertyWiringOptions.None)
    {
        if (builder == null)
        {
            throw new ArgumentNullException(nameof(builder));
        }
        if (handlerType == null)
        {
            throw new ArgumentNullException(nameof(handlerType));
        }

        builder.RegisterAssemblyTypes(handlerType.Assembly)
        .Where(t => t.IsClass && !t.IsAbstract && t.GetInterfaces().Any(IsRebusHandler))
        .As(GetImplementedHandlerInterfaces)
        .InstancePerDependency()
        .PropertiesAutowired(propertyWiringOptions);
    }
Exemple #7
0
        PropertiesAutowired <TLimit, TActivatorData, TRegistrationStyle>(
            this IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> registration, PropertyWiringOptions wiringFlags = PropertyWiringOptions.None)
        {
            var preserveSetValues         = (int)(wiringFlags & PropertyWiringOptions.PreserveSetValues) != 0;
            var allowCircularDependencies = (int)(wiringFlags & PropertyWiringOptions.AllowCircularDependencies) != 0;

            return(registration.PropertiesAutowired(new DefaultPropertySelector(preserveSetValues), allowCircularDependencies));
        }
Exemple #8
0
        MyPropertiesAutowired <TLimit, TActivatorData, TRegistrationStyle>(
            this IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> registration, PropertyWiringOptions wiringFlags = PropertyWiringOptions.None, IPropertySelector propertySelector = null)
        {
            var preserveSetValues         = (int)(wiringFlags & PropertyWiringOptions.PreserveSetValues) != 0;
            var allowCircularDependencies = (int)(wiringFlags & PropertyWiringOptions.AllowCircularDependencies) != 0;

            if (propertySelector == null)
            {
                propertySelector = new DefaultPropertySelector(preserveSetValues);
            }
            if (allowCircularDependencies)
            {
                registration.RegistrationData.ActivatedHandlers.Add((s, e) => AutowiringPropertyInjector.InjectProperties(e.Context, e.Instance, propertySelector, e.Parameters));
            }
            else
            {
                registration.RegistrationData.ActivatingHandlers.Add((s, e) => AutowiringPropertyInjector.InjectProperties(e.Context, e.Instance, propertySelector, e.Parameters));
            }

            return(registration);
            //return registration.PropertiesAutowired(new DefaultPropertySelector(preserveSetValues), allowCircularDependencies);
        }
Exemple #9
0
        CustomPropertiesAutowired <TLimit, TActivatorData, TRegistrationStyle>(
            this IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> registration, PropertyWiringOptions wiringFlags = PropertyWiringOptions.None)
        {
            var allowCircularDependencies = 0 != (int)(wiringFlags & PropertyWiringOptions.AllowCircularDependencies);
            var preserveSetValues         = 0 != (int)(wiringFlags & PropertyWiringOptions.PreserveSetValues);

            if (allowCircularDependencies)
            {
                registration.RegistrationData.ActivatedHandlers.Add((s, e) => Gdot.Care.Common.Dependency.AutowiringPropertyInjector.InjectProperties(e.Context, e.Instance, !preserveSetValues));
            }
            else
            {
                registration.RegistrationData.ActivatingHandlers.Add((s, e) => Gdot.Care.Common.Dependency.AutowiringPropertyInjector.InjectProperties(e.Context, e.Instance, !preserveSetValues));
            }

            return(registration);
        }