Exemplo n.º 1
0
        /// <summary>
        /// 统一注册Adnc.Webpi通用服务
        /// </summary>
        /// <typeparam name="TPermissionHandler"></typeparam>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <param name="environment"></param>
        /// <param name="serviceInfo"></param>
        /// <param name="completedExecute"></param>
        /// <returns></returns>
        public static IServiceCollection AddAdncServices <TPermissionHandler>(this IServiceCollection services
                                                                              , IConfiguration configuration
                                                                              , IWebHostEnvironment environment
                                                                              , ServiceInfo serviceInfo
                                                                              , Action <SharedServicesRegistration> completedExecute = null)
            where TPermissionHandler : PermissionHandler
        {
            services.AddSingleton(serviceInfo);
            services.AddScoped <UserContext>();
            services.AddHttpContextAccessor();
            services.AddMemoryCache();

            var _srvRegistration = new SharedServicesRegistration(configuration, services, environment, serviceInfo);

            _srvRegistration.Configure();
            _srvRegistration.AddControllers();
            _srvRegistration.AddJWTAuthentication();
            _srvRegistration.AddAuthorization <TPermissionHandler>();
            _srvRegistration.AddCors();
            _srvRegistration.AddHealthChecks();
            _srvRegistration.AddEfCoreContext();
            _srvRegistration.AddMongoContext();
            _srvRegistration.AddCaching();
            _srvRegistration.AddSwaggerGen();

            var policies          = _srvRegistration.GenerateDefaultRefitPolicies();
            var authServerAddress = (environment.IsProduction() || environment.IsStaging()) ? "adnc.usr.webapi" : "http://localhost:5010";

            _srvRegistration.AddRpcService <IAuthRpcService>(authServerAddress, policies);

            var maintServiceAddress = (environment.IsProduction() || environment.IsStaging()) ? "adnc.maint.webapi" : "http://localhost:5020";

            _srvRegistration.AddRpcService <IMaintRpcService>(maintServiceAddress, policies);

            completedExecute?.Invoke(_srvRegistration);

            return(services);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 统一注册Adnc.Webpi通用服务
        /// </summary>
        /// <typeparam name="TPermissionHandler"></typeparam>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <param name="environment"></param>
        /// <param name="serviceInfo"></param>
        /// <param name="completedExecute"></param>
        /// <returns></returns>
        public static IServiceCollection AddAdncServices <TPermissionHandler>(this IServiceCollection services
                                                                              , Action <SharedServicesRegistration> completedExecute = null)
            where TPermissionHandler : PermissionHandler
        {
            var configuration = services.GetConfiguration();
            var serviceInfo   = services.GetServiceInfo();
            var environment   = services.GetHostEnvironment();

            services.AddHttpContextAccessor();
            services.AddMemoryCache();

            services.AddHostedService <ChannelConsumersHostedService>();
            services.AddHostedService <CacheAndBloomFilterHostedService>();
            services.AddHostedService(provider =>
            {
                var wokerNode   = provider.GetService <WorkerNode>();
                var logger      = provider.GetService <ILogger <WorkerNodeHostedService> >();
                var serviceName = serviceInfo.ShortName;
                return(new WorkerNodeHostedService(logger, wokerNode, serviceName));
            });

            var _srvRegistration = new SharedServicesRegistration(configuration, services, environment, serviceInfo);

            _srvRegistration.Configure();
            _srvRegistration.AddControllers();
            _srvRegistration.AddJWTAuthentication();
            _srvRegistration.AddAuthorization <TPermissionHandler>();
            _srvRegistration.AddCors();
            _srvRegistration.AddHealthChecks();
            _srvRegistration.AddEfCoreContext();
            _srvRegistration.AddMongoContext();
            _srvRegistration.AddSwaggerGen();
            //_srvRegistration.AddHangfire();

            completedExecute?.Invoke(_srvRegistration);

            return(services);
        }