/// <summary> /// 启动工作流 /// </summary> /// <param name="startup"></param> /// <param name="executingRepository"></param> /// <param name="jsonSerializer"></param> /// <param name="templateRepository"></param> /// <param name="serialTaskStrategy"></param> /// <param name="taskschedStrategy"></param> /// <param name="environmentInit"></param> /// <returns></returns> public static ApplicationStartup UseWorlFlow(this ApplicationStartup startup, ITemplateRepository templateRepository, IExecutingRepository executingRepository, IJsonSerializer jsonSerializer, ITaskschedStrategy taskschedStrategy, ISerialTaskStrategy serialTaskStrategy, Action <IWorkFlowEngine> environmentInit) { if (startup.Items.ContainsKey("UseWorlFlow")) { return(startup); } startup.ServiceRegister.RegisterInstance <ITemplateRepository>(templateRepository); startup.ServiceRegister.RegisterInstance <IExecutingRepository>(executingRepository); var engine = new WorkFlowEngine(templateRepository, executingRepository, jsonSerializer, taskschedStrategy ?? new DefaultTaskschedStrategy(), serialTaskStrategy ?? new DefaultSerialTaskStrategy()) { ApplicationStartup = startup, }; startup.ServiceRegister.RegisterInstance <IWorkFlowEngine>(engine); startup.RegisterStartService(new StartupService(environmentInit, engine)); startup.Items["UseWorlFlow"] = "true"; return(startup); }
/// <summary> /// 启用Api路由健康报告信息 /// </summary> /// <param name="startup">启动信息</param> /// <param name="a10HealthReport">A10报告</param> /// <param name="secondInterval">每个A10文件的检查间隔,以秒为单位,最小时间为10秒</param> /// <param name="initApiRouteProviderMethod">初始化路由提供者</param> /// <param name="loggerBuilder">日志</param> /// <returns></returns> public static ApplicationStartup UseApiUriRouteDispatch(this ApplicationStartup startup, int secondInterval, IA10HealthReport a10HealthReport, Func <IA10HealthReport, IEnumerable <IApiRouteProvider> > initApiRouteProviderMethod, Func <ILoggerBuilder> loggerBuilder) { startup.RegisterStartService(new StartupService(secondInterval < 10 ? 10 : secondInterval, initApiRouteProviderMethod, a10HealthReport) { LoggerBuilder = loggerBuilder }); return(startup); }
/// <summary> /// 启动mvc的ModelState验证 /// </summary> /// <param name="startup"></param> /// <returns></returns> public static ApplicationStartup UseMvcModelStateValidation(this ApplicationStartup startup) { if (startup.Items.ContainsKey("UseMvcModelStateValidation")) { return(startup); } startup.RegisterStartService(new StartupService()); startup.Items["UseMvcModelStateValidation"] = "t"; return(startup); }
/// <summary> /// 启动mvc Ioc注入支持 /// </summary> /// <param name="startup"></param> /// <returns></returns> public static ApplicationStartup UseMvcDependency(this ApplicationStartup startup, IServiceCollection services) { if (startup.Items.ContainsKey("UseMvcDependency")) { return(startup); } startup.Items["UseMvcDependency"] = "t"; startup.RegisterStartService(new ApiStartService()); return(new ApiServiceCollection(services).Populate(startup)); }
/// <summary> /// 启动Api统一接口资源请求 /// </summary> /// <param name="startup">启动环境</param> /// <param name="configuration">The configuration.</param> /// <returns></returns> public static ApplicationStartup UseApiActionCustomRoute(this ApplicationStartup startup, HttpConfiguration configuration) { var controller = new CustomHttpControllerSelector(configuration); var action = new CustomHttpActionSelector(controller); configuration.Services.Replace(typeof(IHttpControllerSelector), controller); configuration.Services.Replace(typeof(IHttpActionSelector), action); startup.RegisterStartService(controller); return(startup); }
/// <summary> /// 启动Api的ModelState验证 /// </summary> /// <param name="startup"></param> /// <returns></returns> public static ApplicationStartup UseApiModelStateValidation(this ApplicationStartup startup) { if (startup.Items.ContainsKey("UseApiModelStateValidation")) { return(startup); } System.Web.Http.GlobalConfiguration.Configuration.Services.Add(typeof(System.Web.Http.Validation.ModelValidatorProvider), new ValidatorProvider()); startup.RegisterStartService(new StartupService()); startup.Items["UseApiModelStateValidation"] = "t"; return(startup); }
public static ApplicationStartup UseMvcModelStateValidation(this ApplicationStartup startup, Microsoft.Extensions.DependencyInjection.IServiceCollection services) { if (startup.Items.ContainsKey("UseMvcModelStateValidation")) { return(startup); } services.Configure <Microsoft.AspNetCore.Mvc.MvcOptions>(opt => { opt.ModelValidatorProviders.Add(new ValidatorProvider()); }); startup.RegisterStartService(new StartupService()); startup.Items["UseMvcModelStateValidation"] = "t"; return(startup); }
/// <summary> /// 自动生成代理,带熔断机制 /// </summary> /// <param name="startup"></param> /// <param name="jsonSerializer"></param> /// <returns></returns> public static ApplicationStartup UseHttpProxyGenerateMessageCircuitBreakerApi(this ApplicationStartup startup, IJsonSerializer jsonSerializer = null, Action <HttpServiceProxyFactory.OnCallingEventArgs> callback = null) { return(startup.RegisterStartService(110, (x) => { var assembly = x.FilteringAssemblyProvider.GetAssemblies().FirstOrDefault(t => t.FullName == typeof(IVCodeService).Assembly.FullName); var provider = new Func <IApiUriDispatcher>(() => new CircuitBreakApiRouteProvider(startup.ServiceLocator.Resolve <ApiUriDispatcher <ApiRouteProvider> >())); foreach (var type in assembly.GetTypes()) { if (type.IsInterface && type.Name.Contains("Service")) { if (type.GetMethods(BindingFlags.Public | BindingFlags.Instance).Any(t => t.GetAttribute <ApiActionRemarkAttribute>() != null)) { var gtype = HttpServiceProxyFactory.CreateProxy(type, provider, jsonSerializer ?? SerializeEnvironment.JsonSerializer, callback); x.ServiceRegister.RegisterType(gtype, type, string.Empty, ComponentLifeStyle.Singleton); } } } })); }
/// <summary> /// 使用权限管理系统 /// </summary> /// <param name="startup">The startup.</param> /// <returns></returns> public static ApplicationStartup UseMvcPermission(this ApplicationStartup startup) { return(startup.RegisterStartService(true, (context) => { var list = new List <ActionResourceAttribute>(300); ActionDesciptors = new List <ActionDesciptor>(100); foreach (var assembly in context.FilteringAssemblyProvider.GetAssemblies()) { if (assembly == null) { continue; } var controllers = from k in assembly.GetTypes() where typeof(BasicController).IsAssignableFrom(k) && !k.IsAbstract && k.IsClass && k.Name.EndsWith("Controller", StringComparison.Ordinal) select k; if (controllers == null || !controllers.Any()) { continue; } var temp = FindAllResourceModule(controllers, (List <ActionDesciptor>)ActionDesciptors); if (temp != null && temp.Any()) { list.AddRange(temp); } } var command = new InitResourceCommand() { Resources = from n in list let leader = n as LeaderActionResourceAttribute let super = n as SuperActionResourceAttribute select new ActionResourceDescriptor() { AggregateId = n.AggregateId, ActionDescn = n.ActionDescn, GroupSort = super != null ? GroupSort.Super : (leader != null ? GroupSort.Leader : GroupSort.Muggle) } }; using (var scope = context.ServiceLocator.BeginLifetimeScope()) { var bus = scope.Resolve <ICommandBus>(); bus.Send(command); } })); //查询资源 IEnumerable <ActionResourceAttribute> FindAllResourceModule(IEnumerable <Type> controllers, List <ActionDesciptor> actionDesciptors) { if (controllers == null || controllers.Count() == 0) { return(null); } var list = new List <ActionResourceAttribute>(controllers.Count() * 10); foreach (var controller in controllers) { foreach (var methodInfo in controller.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)) { /*判断匿名访问资源*/ var allowAnonymousAttributes = methodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), false); if (allowAnonymousAttributes != null && allowAnonymousAttributes.Any()) { continue; } var attributes = methodInfo.GetCustomAttributes(typeof(ActionResourceAttribute), true) as IEnumerable <ActionResourceAttribute>; //没有属性,则不受管理 if (attributes == null || attributes.Count() <= 0) { continue; } var attribute = attributes.FirstOrDefault(); if (list.FirstOrDefault(o => o.AggregateId.Equals(attribute.AggregateId)) != null) { throw new Exception(string.Format("存在多个相同的id:{0},会引起分配权限混乱", attribute.AggregateId)); } actionDesciptors.Add(new ActionDesciptor() { ActionResult = methodInfo.Name, Controller = controller.Name, AggregateId = attribute.AggregateId, Area = Regex.Match(controller.FullName, "\\.Areas\\.(?<name>\\w+)\\.Controllers", RegexOptions.IgnoreCase).Groups["name"].Value, }); list.Add(attribute); } } return(list); } }
/// <summary> /// 启动api Ioc注入支持 /// </summary> /// <param name="startup">The startup.</param> /// <param name="configuration">The configuration.</param> /// <returns></returns> public static ApplicationStartup UseApiDependency(this ApplicationStartup startup, HttpConfiguration configuration) { configuration.DependencyResolver = new DependencyResolver(); startup.RegisterStartService(new ApiStartService()); return(startup); }