Exemplo n.º 1
0
        /// <summary>
        /// 以中间件的方式添加 Cfms 领域驱动服务
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddCfmService(
            this IServiceCollection services)
        {
            //// 领域服务名缓存服务
            //services.AddSingleton<ApiNamesService>();
            //// 激活中间件工厂
            //services.AddTransient(provider => new AppServiceMiddleware(provider));
            // 控制器功能提供程序模式
            services.AddMvcCore(options =>
            {
                // 添加领域服务路由变换约定
                var routeToken = new RouteTokenTransformerConvention(new AppServiceParameterTransformer());
                options.Conventions.Add(routeToken);
            })
            .ConfigureApplicationPartManager(manager =>
            {
                // 添加领域驱动服务功能提供程序到功能集中
                var provider = new AppServiceControllerFeatureProvider();
                manager.FeatureProviders.Add(provider);
            });
            // 微服务网关(config 中还需调用 UseOcelot().Wait())
            //services.AddOcelot();

            return(services);
        }
        public void Apply_NullAttributeRouteModel_NoOp()
        {
            // Arrange
            var convention = new RouteTokenTransformerConvention(new TestParameterTransformer());

            var model = new ActionModel(GetMethodInfo(), Array.Empty <object>());

            model.Selectors.Add(new SelectorModel()
            {
                AttributeRouteModel = null
            });

            // Act
            convention.Apply(model);

            // Assert
            Assert.Null(model.Selectors[0].AttributeRouteModel);
        }
    public void Apply_HasAttributeRouteModel_SetRouteTokenTransformer()
    {
        // Arrange
        var transformer = new TestParameterTransformer();
        var convention  = new RouteTokenTransformerConvention(transformer);

        var model = new ActionModel(GetMethodInfo(), Array.Empty <object>());

        model.Selectors.Add(new SelectorModel()
        {
            AttributeRouteModel = new AttributeRouteModel()
        });

        // Act
        convention.Apply(model);

        // Assert
        Assert.Same(transformer, model.RouteParameterTransformer);
    }
Exemplo n.º 4
0
        public void Apply_HasAttributeRouteModel_SetRouteTokenTransformer()
        {
            // Arrange
            var transformer = new TestParameterTransformer();
            var convention  = new RouteTokenTransformerConvention(transformer);

            var model = new ActionModel(GetMethodInfo(), Array.Empty <object>());

            model.Selectors.Add(new SelectorModel()
            {
                AttributeRouteModel = new AttributeRouteModel()
            });

            // Act
            convention.Apply(model);

            // Assert
            Assert.True(model.Properties.TryGetValue(typeof(IOutboundParameterTransformer), out var routeTokenTransformer));
            Assert.Equal(transformer, routeTokenTransformer);
        }
Exemplo n.º 5
0
        public static IServiceCollection AddConfiguredMvc(this IServiceCollection services)
        {
            var parameterTransformer = new SlugifyParameterTransformer();

            IMvcBuilder mvc = services.AddMvc(options =>
            {
                var convention = new RouteTokenTransformerConvention(parameterTransformer);
                options.Conventions.Add(convention);
            });

            mvc.AddRazorPagesOptions(options =>
            {
                var convention = new PageRouteTransformerConvention(parameterTransformer);
                options.Conventions.Add(convention);
            });

            mvc.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
            mvc.AddDataAnnotationsLocalization(options =>
            {
                options.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(SharedResources));
            });

            return(services);
        }