Пример #1
0
            /// <summary>
            /// Directs StructureMap to always inject dependencies into any and all public Setter properties
            /// of the type TPluginType.
            /// </summary>
            /// <typeparam name="TPluginType"></typeparam>
            /// <returns></returns>
            public CreatePluginFamilyExpression <TPluginType> FillAllPropertiesOfType <TPluginType>()
            {
                Func <PropertyInfo, bool> predicate = prop => prop.PropertyType == typeof(TPluginType);

                alter = graph => graph.Policies.SetterRules.Add(predicate);

                return(_parent.For <TPluginType>());
            }
Пример #2
0
        /// <summary>
        /// Populates the registry using the specified service descriptors.
        /// </summary>
        /// <remarks>
        /// This method should only be called once per container.
        /// </remarks>
        /// <param name="registry">The registry.</param>
        /// <param name="descriptors">The service descriptors.</param>
        public static void Populate(this Registry registry, IEnumerable <ServiceDescriptor> descriptors)
        {
            // HACK: We insert this action in order to prevent Populate being called twice on the same container.
            registry.Configure(ThrowIfMarkerInterfaceIsRegistered);

            registry.For <IMarkerInterface>();

            registry.Policies.ConstructorSelector <AspNetConstructorSelector>();

            registry.For <IServiceProvider>()
            .LifecycleIs(Lifecycles.Container)
            .Use <StructureMapServiceProvider>();

            registry.For <IServiceScopeFactory>()
            .LifecycleIs(Lifecycles.Container)
            .Use <StructureMapServiceScopeFactory>();

            registry.Register(descriptors);
        }
        /// <summary>
        /// Adds a JustSaying message handler to the registry.
        /// </summary>
        /// <typeparam name="TMessage">The type of the message handled.</typeparam>
        /// <typeparam name="THandler">The type of the message handler to register.</typeparam>
        /// <param name="registry">The <see cref="Registry"/> to add the message handler to.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="registry"/> is <see langword="null"/>.
        /// </exception>
        public static void AddJustSayingHandler <TMessage, THandler>(this Registry registry)
            where TMessage : Message
            where THandler : class, IHandlerAsync <TMessage>
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            registry.For <IHandlerAsync <TMessage> >().Use <THandler>();
        }