Пример #1
0
        public static IWorkFlowEngine IoCCreate()
        {
            var app = new Never.ApplicationStartup(IoC.Providers.AppDomainAssemblyProvider.Default)
                      .RegisterAssemblyFilter("Never".CreateAssemblyFilter())
                      .UsePublishSubscribeBus()
                      .UseEasyIoC((x, y, z) =>
            {
                x.RegisterCallBack("eee", ComponentLifeStyle.Singleton, () => new IoCMySqlTemplateRepository());
            })
                      .UseWorlFlow(new IoCMySqlTemplateRepository(), new IoCMySqlExecutingRepository(), new Never.Serialization.EasyJsonSerializer(), (w) =>
            {
                w.TemplateEngine.Register(new Template("请病假申请").Next <请假申请>().Next <组长审批, 主管审批>(CoordinationMode.Meanwhile).Next <人事审批>().End());
                w.TemplateEngine.Register(new Template("请节日假申请").Next <请假申请>().Next <组长审批>().Next <人事审批>().End());
                w.TemplateEngine.Register(new Template("请婚姻假申请").Next <请假申请>().Next <组长审批, 主管审批>().Next <人事审批>().End());
                w.TemplateEngine.TestCompliant += (o, e) =>
                {
                    e.Register <请假申请>(new 请假申请消息(), (x, y) => { return(y is 请假申请消息); });
                    e.Register <主管审批>(new 主管审批意见结果(), (x, y) => { return(y is 请假申请消息); });
                    e.Register <组长审批>(new 组长审批意见结果(), (x, y) => { return(y is 请假申请消息); });
                    e.Register <人事审批>(new 人事审批请假意见结果(), (x, y) => { return(y is 组长审批意见结果 || y is 主管审批意见结果); });
                };
            })
                      .Startup(x =>
            {
            });

            var eee = app.ServiceLocator.Resolve <IoCMySqlTemplateRepository>("eee");

            eee = app.ServiceLocator.Resolve <IoCMySqlTemplateRepository>();
            return(app.ServiceLocator.Resolve <IWorkFlowEngine>("abc"));
        }
Пример #2
0
        /// <summary>
        /// 使用强制检查事件是否带上了<see cref="Never.EventStreams.EventAppDomainStartupService"/>特性
        /// </summary>
        /// <param name="startup">The startup.</param>
        /// <returns></returns>
        public static ApplicationStartup UseForceCheckEventAppDomainAttribute(this ApplicationStartup startup)
        {
            if (startup.Items.ContainsKey("UseForceCheckEventAppDomainAttribute"))
            {
                return(startup);
            }

            startup.RegisterStartService(new EventAppDomainStartupService());
            return(startup);
        }
Пример #3
0
        /// <summary>
        /// 使用强制聚合根有Handle方法但没有实现<see cref="Never.Domains.IHandle{TEvent}"/>接口
        /// </summary>
        /// <param name="startup">The startup.</param>
        /// <returns></returns>
        public static ApplicationStartup UseForceCheckAggregateRootImplIHandle(this ApplicationStartup startup)
        {
            if (startup.Items.ContainsKey("UseForceCheckAggregateRootImplIHandle"))
            {
                return(startup);
            }

            startup.RegisterStartService(new AggregateRootIHandleStartService());
            return(startup);
        }
Пример #4
0
        /// <summary>
        /// 使用强制检查EventHandler的构造函数是否在IoC可以构造出来
        /// </summary>
        /// <param name="ignoreTypes">忽略的对象</param>
        /// <param name="startup"></param>
        /// <returns></returns>
        public static ApplicationStartup UseForceCheckEventHandlerCtor(this ApplicationStartup startup, IEnumerable <Type> ignoreTypes)
        {
            if (startup.Items.ContainsKey("UseForceCheckEventHandlerCtor"))
            {
                return(startup);
            }

            startup.RegisterStartService(true, (x) => { x.ProcessType(new[] { new EventStartupService.EventHandlerCtorParameterProcessor(ignoreTypes ?? Type.EmptyTypes) }); });
            return(startup);
        }
Пример #5
0
        /// <summary>
        /// 注入commandhanler和eventhandler
        /// </summary>
        /// <param name="startup"></param>
        /// <param name="lifeStyle"></param>
        /// <returns></returns>
        public static ApplicationStartup UseInjectingCommandHandlerEventHandler(this ApplicationStartup startup, ComponentLifeStyle lifeStyle)
        {
            if (startup.Items.ContainsKey("UseInjectCommandHandlerEventHandler"))
            {
                return(startup);
            }

            startup.RegisterStartService(new Never.Domains.StartupService(lifeStyle));
            return(startup);
        }
Пример #6
0
        /// <summary>
        /// 使用强制检查Event的是存在没有参数的构造函数
        /// </summary>
        /// <param name="ignoreTypes">忽略的对象</param>
        /// <param name="startup"></param>
        /// <returns></returns>
        public static ApplicationStartup UseForceCheckCommandEvenWithNoParamaterCtor(this ApplicationStartup startup, IEnumerable <Type> ignoreTypes = null)
        {
            if (startup.Items.ContainsKey("UseForceCheckEventHandlerCtor"))
            {
                return(startup);
            }

            startup.RegisterStartService(int.MaxValue, (x) => { x.ProcessType(new[] { new CommandStartupService.CommandNoCtorParamaterProcessor(ignoreTypes ?? Type.EmptyTypes) }); });
            startup.RegisterStartService(int.MaxValue, (x) => { x.ProcessType(new[] { new EventStartupService.EventNoCtorParamaterProcessor(ignoreTypes ?? Type.EmptyTypes) }); });
            return(startup);
        }
Пример #7
0
        /// <summary>
        /// 使用强制检查MessageSubscriber的构造函数是否在IoC可以构造出来
        /// </summary>
        /// <param name="ignoreTypes">忽略的对象</param>
        /// <param name="startup"></param>
        /// <returns></returns>
        public static ApplicationStartup UseForceCheckMessageSubscriberCtor(this ApplicationStartup startup, IEnumerable <Type> ignoreTypes)
        {
            if (startup.Items.ContainsKey("UseForceCheckMessageSubscriberCtor"))
            {
                return(startup);
            }

            startup.RegisterStartService(true, (x) =>
            {
                x.ProcessType(new[] { new MessageStartupService.MessageHandlerCtorProcessor(ignoreTypes) });
            });

            return(startup);
        }
Пример #8
0
        /// <summary>
        /// 【服务端】开户处理远程调用
        /// </summary>
        /// <param name="startup"></param>
        /// <param name="handler"></param>
        /// <param name="listeningEndPoint"></param>
        /// <returns></returns>
        public static ApplicationStartup UseHttpRemoteResponseHandler(this ApplicationStartup startup, System.Net.EndPoint listeningEndPoint, Remoting.IResponseHandler handler)
        {
            if (startup.Items.ContainsKey("UseHttpRemoteResponseHandler"))
            {
                return(startup);
            }

            var service = new Remoting.ServerRequestHandler(listeningEndPoint, handler, new Remoting.Http.Protocol());

            startup.RegisterStartService(20, (x) => { service.Startup(); });

            startup.Items["UseHttpRemoteResponseHandler"] = "t";
            return(startup);
        }
Пример #9
0
        /// <summary>
        /// 启动MemoryCache支持
        /// </summary>
        /// <param name="startup">程序宿主环境配置服务</param>
        /// <param name="key">IoC容器中的key</param>
        /// <returns></returns>
        public static ApplicationStartup UseMemoryCache(this ApplicationStartup startup, string key)
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseMemoryCache" + key))
            {
                return(startup);
            }
            startup.ServiceRegister.RegisterType(typeof(Never.Caching.MemoryCache), typeof(ICaching), key, ComponentLifeStyle.Singleton);
            startup.Items["UseMemoryCache" + key] = "t";
            return(startup);
        }
Пример #10
0
        /// <summary>
        /// 【客户端】开户请求远程调用
        /// </summary>
        /// <param name="startup"></param>
        /// <param name="key"></param>
        /// <param name="serverEndPoint"></param>
        /// <returns></returns>
        public static ApplicationStartup UseHttpRemoteRequestHandler(this ApplicationStartup startup, string key, System.Net.EndPoint serverEndPoint)
        {
            if (startup.Items.ContainsKey(string.Concat("UseHttpRemoteRequestHandler", key)))
            {
                return(startup);
            }

            var client = new Remoting.ClientRequestHadler(serverEndPoint, new Remoting.Http.Protocol());

            startup.ServiceRegister.RegisterInstance(client, typeof(Remoting.IRequestHandler), key);
            startup.RegisterStartService(true, (x) => { client.Startup(); });

            startup.Items[string.Concat("UseHttpRemoteRequestHandler", key)] = "t";
            return(startup);
        }
Пример #11
0
        /// <summary>
        /// 使用空的事件总线
        /// </summary>
        /// <param name="startup"></param>
        /// <returns></returns>
        public static ApplicationStartup UseEmptyEventBus(this ApplicationStartup startup)
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseEmptyEventBus"))
            {
                return(startup);
            }

            startup.ServiceRegister.RegisterInstance(EmptyEventBus.Only, typeof(IEventBus));
            startup.Items["UseEmptyEventBus"] = "t";
            return(startup);
        }
Пример #12
0
        /// <summary>
        /// 使用事件总线,通常配合CommandBus来使用
        /// </summary>
        /// <param name="startup"></param>
        /// <returns></returns>
        public static ApplicationStartup UseEventBus(this ApplicationStartup startup)
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseEventBus"))
            {
                return(startup);
            }

            startup.ServiceRegister.RegisterType(typeof(EventBus), typeof(IEventBus), string.Empty, ComponentLifeStyle.Singleton);
            startup.Items["UseEventBus"] = "t";
            return(startup);
        }
Пример #13
0
        /// <summary>
        /// 启动ThreadContextCache支持
        /// </summary>
        /// <param name="startup">程序宿主环境配置服务</param>
        /// <param name="key">IoC容器中的key</param>
        /// <returns></returns>
        public static ApplicationStartup UseThreadContextCache(this ApplicationStartup startup, string key)
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseThreadContextCache" + key))
            {
                return(startup);
            }

            startup.ServiceRegister.RegisterType(typeof(ThreadContextCache), typeof(ICaching), key, ComponentLifeStyle.Scoped);
            startup.Items["UseThreadContextCache" + key] = "t";
            return(startup);
        }
Пример #14
0
        /// <summary>
        /// 启动ConcurrentCache支持
        /// </summary>
        /// <param name="startup">程序宿主环境配置服务</param>
        /// <param name="key">IoC容器中的key</param>
        /// <param name="lifeStyle">生命周期</param>
        /// <returns></returns>
        public static ApplicationStartup UseConcurrentCache(this ApplicationStartup startup, string key, ComponentLifeStyle lifeStyle)
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseConcurrentCache" + key))
            {
                return(startup);
            }

            startup.ServiceRegister.RegisterType(typeof(ConcurrentCounterDictCache), typeof(ICaching), key, lifeStyle);
            startup.Items["UseConcurrentCache" + key] = "t";

            return(startup);
        }
Пример #15
0
        /// <summary>
        /// 启动空消息生产者支持
        /// </summary>
        /// <param name="startup">程序宿主环境配置服务</param>
        /// <returns></returns>
        public static ApplicationStartup UseEmptyroducer(this ApplicationStartup startup)
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseEmptyroducer"))
            {
                return(startup);
            }

            startup.ServiceRegister.RegisterInstance(EmptyMessageProducer.Empty, typeof(IMessageProducer), string.Empty);

            startup.Items["UseEmptyroducer"] = "t";
            return(startup);
        }
Пример #16
0
        /// <summary>
        /// 启用发布订阅模式,生命周期通常声明为单例
        /// </summary>
        /// <typeparam name="TMessageContext">事件上下文</typeparam>
        /// <param name="startup">程序宿主环境配置服务</param>
        /// <param name="lifeStyle">生命周期</param>
        /// <returns></returns>
        public static ApplicationStartup UsePublishSubscribeBus <TMessageContext>(this ApplicationStartup startup, ComponentLifeStyle lifeStyle) where TMessageContext : IMessageContext
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UsePublishSubscribeBus"))
            {
                return(startup);
            }

            /*注册发布事件*/
            startup.ServiceRegister.RegisterType(typeof(MessagePublisher), typeof(IMessagePublisher), string.Empty, ComponentLifeStyle.Singleton);
            startup.ServiceRegister.RegisterType(typeof(TMessageContext), typeof(IMessageContext), string.Empty, ComponentLifeStyle.Transient);
            startup.RegisterStartService(new Never.Messages.StartupService(lifeStyle));
            startup.Items["UsePublishSubscribeBus"] = "t";
            return(startup);
        }
Пример #17
0
        /// <summary>
        /// 启动msmq生产者支持
        /// </summary>
        /// <param name="startup">程序宿主环境配置服务</param>
        /// <param name="route">msmq的配置路由</param>
        /// <param name="key">IoC容器中的key</param>
        /// <returns></returns>
        public static ApplicationStartup UseMSMQProducer(this ApplicationStartup startup, MessageConnection route, string key)
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (route == null)
            {
                throw new Exception("当前消息链接对象为空");
            }

            if (string.IsNullOrEmpty(route.ConnetctionString))
            {
                throw new Exception("当前消息链接对象字符串为空");
            }

            startup.ServiceRegister.RegisterInstance(new Producer(route), typeof(IMessageProducer), key);
            return(startup);
        }
Пример #18
0
        /// <summary>
        /// 启动Serializer支持
        /// </summary>
        /// <param name="startup">程序宿主环境配置服务</param>
        /// <param name="key">key</param>
        /// <returns></returns>
        public static ApplicationStartup UseDataContractJson(this ApplicationStartup startup, string key = "ioc.ser.datacontract")
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseDataContractJson"))
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseDataContractJson"))
            {
                return(startup);
            }

            startup.ServiceRegister.RegisterType(typeof(DataContractSerializer), typeof(IJsonSerializer), key, ComponentLifeStyle.Singleton);
            startup.Items["UseDataContractJson"] = "t";
            return(startup);
        }
Пример #19
0
        /// <summary>
        /// 启动Serializer支持
        /// </summary>
        /// <param name="startup">程序宿主环境配置服务</param>
        /// <param name="key">key</param>
        /// <returns></returns>
        public static ApplicationStartup UseEasyJson(this ApplicationStartup startup, string key = "ioc.ser.easyjson")
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseEasyJson"))
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseEasyJson"))
            {
                return(startup);
            }

            startup.ServiceRegister.RegisterInstance(new EasyJsonSerializer(), typeof(IJsonSerializer), key);

            startup.Items["UseEasyJson"] = "t";
            return(startup);
        }
Пример #20
0
 public static ApplicationStartup UseInprocEventProviderCommandBus <TCommandContext>(this ApplicationStartup startup, IEventStorager eventStorager)
     where TCommandContext : ICommandContext
 {
     return(UseInprocEventProviderCommandBus <TCommandContext>(startup, eventStorager, EmptyCommandStreamStorager.Empty));
 }
Пример #21
0
 /// <summary>
 /// 在sampleioc中自动使用属性发现注入
 /// </summary>
 /// <param name="startup"></param>
 /// <param name="providers"></param>
 /// <returns></returns>
 public static ApplicationStartup UseAutoInjectingAttributeUsingIoC(this ApplicationStartup startup, IAutoInjectingEnvironmentProvider[] providers)
 {
     startup.RegisterStartService(new AutoInjectingStartupService(providers));
     return(startup);
 }
Пример #22
0
 /// <summary>
 /// 使用强制检查EventHandler的构造函数是否在IoC可以构造出来
 /// </summary>
 /// <param name="startup"></param>
 /// <returns></returns>
 public static ApplicationStartup UseForceCheckEventHandlerCtor(this ApplicationStartup startup)
 {
     return(UseForceCheckEventHandlerCtor(startup, new Type[0]));
 }
Пример #23
0
 /// <summary>
 /// 启动msmq生产者支持
 /// </summary>
 /// <param name="startup">程序宿主环境配置服务</param>
 /// <param name="route">msmq的配置路由</param>
 /// <returns></returns>
 public static ApplicationStartup UseMSMQProducer(this ApplicationStartup startup, MessageConnection route)
 {
     return(UseMSMQProducer(startup, route, string.Empty));
 }
Пример #24
0
 public static ApplicationStartup UseMQEventProviderCommandBus <TCommandContext>(this ApplicationStartup startup, IMessageProducerProvider messageProducerProvider, IEventStorager eventStorager) where TCommandContext : ICommandContext
 {
     return(UseMQEventProviderCommandBus <TCommandContext>(startup, messageProducerProvider, eventStorager, EmptyCommandStreamStorager.Empty));
 }
Пример #25
0
 /// <summary>
 /// 启动ThreadContextCache支持
 /// </summary>
 /// <param name="startup">程序宿主环境配置服务</param>
 /// <returns></returns>
 public static ApplicationStartup UseThreadContextCache(this ApplicationStartup startup)
 {
     return(UseThreadContextCache(startup, string.Empty));
 }
Пример #26
0
        public static ApplicationStartup UseMQEventProviderCommandBus <TCommandContext>(this ApplicationStartup startup, IMessageProducerProvider messageProducerProvider, IEventStorager eventStorager, ICommandStorager commandStorager) where TCommandContext : ICommandContext
        {
            if (startup.ServiceRegister == null)
            {
                return(startup);
            }

            if (startup.Items.ContainsKey("UseMQEventProviderCommandBus"))
            {
                return(startup);
            }

            if (startup.Items.Remove("UseInprocEventProviderCommandBus"))
            {
                throw new ArgumentNullException("系统已经注册同进程模式的命令总线了,两者不同共存");
            }

            /*注册发布事件*/
            startup.ServiceRegister.RegisterType(typeof(TCommandContext), typeof(ICommandContext), string.Empty, ComponentLifeStyle.Transient);
            startup.ServiceRegister.RegisterType(typeof(DefaultEventContext), typeof(IEventContext), string.Empty, ComponentLifeStyle.Transient);
            startup.ServiceRegister.RegisterInstance(messageProducerProvider ?? new DefaultMessageProducerProvider(), typeof(IMessageProducerProvider), string.Empty);
            startup.ServiceRegister.RegisterType(typeof(MQEventProviderCommandBus), typeof(ICommandBus), string.Empty, ComponentLifeStyle.Singleton);
            startup.ServiceRegister.RegisterInstance(eventStorager ?? EmptyEventStreamStorager.Empty, typeof(IEventStorager), string.Empty);
            startup.ServiceRegister.RegisterInstance(commandStorager ?? EmptyCommandStreamStorager.Empty, typeof(ICommandStorager), string.Empty);

            //注入handler类型的对象
            startup.UseInjectingCommandHandlerEventHandler(ComponentLifeStyle.Singleton);

            startup.Items["UseMQEventProviderCommandBus"] = "t";
            return(startup);
        }
Пример #27
0
 /// <summary>
 /// 启动ConcurrentCache支持
 /// </summary>
 /// <param name="startup">程序宿主环境配置服务</param>
 /// <returns></returns>
 public static ApplicationStartup UseConcurrentCache(this ApplicationStartup startup)
 {
     return(UseConcurrentCache(startup, string.Empty));
 }
Пример #28
0
 /// <summary>
 /// 启动CounterCache支持
 /// </summary>
 /// <param name="startup">程序宿主环境配置服务</param>
 /// <returns></returns>
 public static ApplicationStartup UseCounterCache(this ApplicationStartup startup)
 {
     return(UseCounterCache(startup, string.Empty, ComponentLifeStyle.Transient));
 }
Пример #29
0
 /// <summary>
 /// 启动ConcurrentCache支持
 /// </summary>
 /// <param name="startup">程序宿主环境配置服务</param>
 /// <param name="key">IoC容器中的key</param>
 /// <returns></returns>
 public static ApplicationStartup UseConcurrentCache(this ApplicationStartup startup, string key)
 {
     return(UseConcurrentCache(startup, key, ComponentLifeStyle.Transient));
 }
Пример #30
0
 public static ApplicationStartup UseMQEventProviderCommandBus(this ApplicationStartup startup, IMessageProducerProvider messageProducerProvider)
 {
     return(UseMQEventProviderCommandBus <DefaultCommandContext>(startup, messageProducerProvider, EmptyEventStreamStorager.Empty));
 }