Пример #1
0
        private void SetupMiddlewarePipeline(ServiceRegistry registry)
        {
            Stack <Type> pipeline = this.GetPipelineStack();

            registry.Scan(x =>
            {
                x.WithDefaultConventions();

                // scan assemblies that we are loading pipelines from
                foreach (Type middlewareType in pipeline)
                {
                    x.AssemblyContainingType(middlewareType);
                }
            });

            registry.For <IMiddleware>().Use <UnhandledMessageMiddleware>();

            if (this._configReader.AboutEnabled)
            {
                registry.For <IMiddleware>().DecorateAllWith <AboutMiddleware>();
            }

            if (this._configReader.StatsEnabled)
            {
                registry.For <IMiddleware>().DecorateAllWith <StatsMiddleware>();
            }

            while (pipeline.Any())
            {
                Type nextType = pipeline.Pop();
                ServiceRegistry.InstanceExpression <IMiddleware> nextDeclare = registry.For <IMiddleware>();

                // using reflection as Structuremap doesn't allow passing types in at the moment :-(
                MethodInfo decorateMethod = nextDeclare.GetType().GetMethod("DecorateAllWith", new[] { typeof(Func <Instance, bool>) });
                if (decorateMethod != null)
                {
                    MethodInfo generic = decorateMethod.MakeGenericMethod(nextType);
                    generic.Invoke(nextDeclare, new object[] { null });
                }
            }

            if (this._configReader.HelpEnabled)
            {
                registry.For <IMiddleware>().DecorateAllWith <HelpMiddleware>();
            }

            registry.For <IMiddleware>().DecorateAllWith <BeginMessageMiddleware>();
        }
        public static LambdaInstance <IServiceContext, TPluginType> InterceptWith <TPluginType, TPluginTypeProxy>(this ServiceRegistry.InstanceExpression <TPluginType> instance, String instanceName, IEnumerable <Type> behaviorTypes)
            where TPluginType : class
            where TPluginTypeProxy : TPluginType
        {
            ICollection <IInterceptionBehavior> behaviors = new List <IInterceptionBehavior>();

            foreach (Type behavior in behaviorTypes)
            {
                behaviors.Add((IInterceptionBehavior)Activator.CreateInstance(behavior));
            }
            return(instance.InterceptWith <TPluginType, TPluginTypeProxy>(instanceName, behaviors));
        }
 public static LambdaInstance <IServiceContext, TPluginType> InterceptWith <TPluginType, TPluginTypeProxy>(this ServiceRegistry.InstanceExpression <TPluginType> instance, String instanceName, IEnumerable <IInterceptionBehavior> behaviors)
     where TPluginType : class
     where TPluginTypeProxy : TPluginType
 {
     return(instance.Use(InterceptorFunctionBuilder.Build <TPluginType, TPluginTypeProxy>(instanceName, behaviors)).Named(instanceName));
 }
        public static LambdaInstance <IServiceContext, TPluginType> InterceptWith <TPluginType, TPluginTypeProxy>(this ServiceRegistry.InstanceExpression <TPluginType> instance, String instanceName, Type behaviorType)
            where TPluginType : class
            where TPluginTypeProxy : TPluginType
        {
            IInterceptionBehavior behavior = (IInterceptionBehavior)Activator.CreateInstance(behaviorType);

            return(instance.InterceptWith <TPluginType, TPluginTypeProxy>(instanceName, behavior));
        }
 public static LambdaInstance <IServiceContext, TPluginType> InterceptWith <TPluginType, TPluginTypeProxy>(this ServiceRegistry.InstanceExpression <TPluginType> instance, IInterceptionBehavior behavior)
     where TPluginType : class
     where TPluginTypeProxy : TPluginType
 {
     return(instance.Use(InterceptorFunctionBuilder.Build <TPluginType, TPluginTypeProxy>(behavior)));
 }