示例#1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimsIdentity.DefaultRoleClaimType;

            string connectionString = ConfigurationManager.ConnectionStrings["ElateServiceConnection"].ConnectionString;
            CustomerServiceModule     customerServiceModule    = new CustomerServiceModule();
            ExecutorServiceModule     executorServiceModule    = new ExecutorServiceModule();
            IndentServiceModule       indentServiceModule      = new IndentServiceModule();
            UserActivityServiceModule userActivityModule       = new UserActivityServiceModule();
            UnitOfWorkModule          unitOfWorkModule         = new UnitOfWorkModule(connectionString);
            UnitOfUserActivityModule  unitOfUserActivityModule = new UnitOfUserActivityModule(connectionString);
            AutoMapperModule          mapperModule             = new AutoMapperModule();
            var kernel = new StandardKernel(customerServiceModule, executorServiceModule, indentServiceModule, userActivityModule,
                                            unitOfWorkModule, unitOfUserActivityModule, mapperModule);

            // Web Api
            // System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new Ninject.Web.WebApi.NinjectDependencyResolver(kernel);

            // MVC
            // System.Web.Mvc.DependencyResolver.SetResolver(new Ninject.Web.Mvc.NinjectDependencyResolver(kernel));
            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
示例#2
0
        public void Test1()
        {
            var configuration = AutoMapperModule.CreateMapperConfiguration <MatchProfile>();

            // Act/Assert
            configuration.AssertConfigurationIsValid();
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add GCConnection
            services.AddDbContext <WebAppDataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")), ServiceLifetime.Scoped);

            services.AddScoped <DbContext>(provider => provider.GetService <WebAppDataContext>());
            services.AddMvcCore()
            .AddAuthorization()
            // .AddJsonFormatters()
            .AddApiExplorer();

            services.AddMvc(option => option.EnableEndpointRouting = false)
            .AddNewtonsoftJson();
            // Add cors
            services.AddCors();

            // Add Register modules.
            ServiceModule.Register(services, Configuration);
            RepositoryModule.Register(services);
            AutoMapperModule.Register(services);

            services.AddMvc();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My API", Version = "v1"
                });
            });
        }
示例#4
0
        public void 配置映射_条件过滤()
        {
            AutoMapperModule.Initialize(new Type[] { typeof(EntityBaseDto), typeof(EntityOrderProfile) });
            var obj2 = obj1.MapTo <EntityBaseDto>();

            Assert.Equal(obj2.EntityOrders.Count(), 3);
        }
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["ElateServiceConnection"].ConnectionString;

            CustomerServiceModule     customerServiceModule    = new CustomerServiceModule();
            ExecutorServiceModule     executorServiceModule    = new ExecutorServiceModule();
            IndentServiceModule       indentServiceModule      = new IndentServiceModule();
            UserActivityServiceModule userActivityModule       = new UserActivityServiceModule();
            UnitOfWorkModule          unitOfWorkModule         = new UnitOfWorkModule(connectionString);
            UnitOfUserActivityModule  unitOfUserActivityModule = new UnitOfUserActivityModule(connectionString);
            AutoMapperModule          mapperModule             = new AutoMapperModule();
            var kernel = new StandardKernel(customerServiceModule, executorServiceModule, indentServiceModule, userActivityModule,
                                            unitOfWorkModule, unitOfUserActivityModule, mapperModule);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                RegisterServices(kernel);
                GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
示例#6
0
        public void isValid()
        {
            // Arrange
            var configuration = AutoMapperModule.CreateMapperConfiguration <QuestionProfile>();

            // Act/Assert
            configuration.AssertConfigurationIsValid();
        }
        public void AutoMapper_Configuration_IsValid()
        {
            // Arrange
            var configuration = AutoMapperModule.CreateMapperConfiguration();

            // Act/Assert
            configuration.AssertConfigurationIsValid();
        }
        public void Test1()
        {
            // Arrange
            var configuration = AutoMapperModule.CreateMapperConfiguration <SurveyUserProfile>();


            // Act
            configuration.AssertConfigurationIsValid();
        }
示例#9
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     _containerProvider = new ContainerProvider(AutofacConfig.ConfigureAutofac());
     AutoMapperModule.Initialize();
 }
示例#10
0
        public void IsValid()
        {
            // Arange
            var configuration1 = AutoMapperModule.CreateMapperConfiguration <OptionProfile>();
            var configuration2 = AutoMapperModule.CreateMapperConfiguration <QuestionProfile>();

            //var configuration = AutoMapperModule.CreateMapperConfiguration<>();
            // Act/Assert
            configuration1.AssertConfigurationIsValid();
            configuration2.AssertConfigurationIsValid();
        }
示例#11
0
        public void 特性自动映射测试()
        {
            AutoMapperModule.Initialize(new Type[] { typeof(EntityBaseDto) });

            var obj2 = obj1.MapTo <EntityBaseDto>();

            Assert.Equal(obj2.Name, "张三");

            var obj3 = obj2.MapTo <Entity>();

            obj3.Name.ShouldBe("张三");
        }
示例#12
0
        public static void ConfigureDependencyInjection()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModule(new AutoMapperModule());
            builder.RegisterModule(new ServiceModule());
            builder.RegisterType <DBContext>().InstancePerRequest();
            AutoMapperModule.ConfigureAutomapperModule(builder);
            ServiceModule.ConfigureServiceModule(builder);
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
示例#13
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            string        connectionString = ConfigurationManager.ConnectionStrings["WebAppConnection"].ConnectionString;
            NinjectModule serviceModule    = new ServiceModule(connectionString);
            NinjectModule autoMapperModule = new AutoMapperModule();

            var kernel = new StandardKernel(serviceModule, autoMapperModule);


            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
示例#14
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // внедрение зависимостей
            NinjectModule registrations = new NinjectRegistrations();
            NinjectModule serviceModule = new ServiceModule();
            NinjectModule autoMapper    = new AutoMapperModule();
            var           kernel        = new StandardKernel(registrations, serviceModule, autoMapper);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
示例#15
0
        public void Profile配置映射_覆盖_Attribute映射()
        {
            AutoMapperModule.Initialize(new Type[] { typeof(EntityBaseDto), typeof(EntityProfile) });

            var obj1 = new Entity()
            {
                Id = 1, Name = "张三"
            };
            var obj2 = obj1.MapTo <EntityBaseDto>();

            Assert.Equal(obj2.Name, "张三");

            var obj3 = obj2.MapTo <Entity>();

            obj3.Name.ShouldBe("张三Test");
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            NinjectModule studentModule = new StudentModule();
            NinjectModule postModule    = new PostModule();
            NinjectModule serviceModule = new ServiceModule();
            NinjectModule tagModule     = new TagModule();
            NinjectModule commentModule = new CommentModule();
            NinjectModule autoMapper    = new AutoMapperModule();
            var           kernel        = new StandardKernel(studentModule, postModule, serviceModule, tagModule, commentModule, autoMapper);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
示例#17
0
        protected void Application_Start()
        {
            Database.SetInitializer <LedContext>(new LedDbInitializer());

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // внедрение зависимостей
            NinjectModule autoMapperModule = new AutoMapperModule();
            NinjectModule cityModule       = new CityModule();
            NinjectModule ownerModule      = new OwnerModule();
            NinjectModule displayModule    = new DisplayModule();
            NinjectModule serviceModule    = new ServiceModule("DefaultConnection");

            var kernel = new StandardKernel(autoMapperModule, cityModule, ownerModule, displayModule, serviceModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
示例#18
0
        private void DependencyInjection()
        {
            // dependency injection
            var dependencesModule = new DependencesModule();

            var autoMapperServerModule = new AutoMapperModule();

            var serviceModule = new ServicesModule("DIMSDBConnection", "DIMSIdentityConnection");

            var kernel = new StandardKernel(dependencesModule, serviceModule, autoMapperServerModule);

            kernel.Bind <DefaultModelValidatorProviders>().ToConstant(new DefaultModelValidatorProviders(GlobalConfiguration.Configuration.Services.GetModelValidatorProviders()));

            kernel.Bind <DefaultFilterProviders>().ToConstant(new DefaultFilterProviders(GlobalConfiguration.Configuration.Services.GetFilterProviders()));

            var ninjectResolver = new NinjectDependencyResolver(kernel);

            DependencyResolver.SetResolver(ninjectResolver);

            GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
        }
示例#19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // 日志配置
            LogConfig();

            #region 跨域
#if DEBUG
            services.AddCors(options =>
                             options.AddPolicy("AllowSameDomain",
                                               builder => builder
                                               .WithOrigins("http://example.com", "http://www.contoso.com")
                                               .AllowAnyMethod()
                                               .AllowAnyHeader()
                                                                   //.AllowAnyOrigin()    //允许任何来源的主机访问(debug开发允许跨域)
                                               .AllowCredentials() //指定处理cookie
                                               ));
#else
            services.AddCors(options => options.AddPolicy("AllowSameDomain", builder => { }));
#endif
            #endregion

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            //替换控制器所有者  http://www.cnblogs.com/GuZhenYin/p/8301500.html
            services.Replace(ServiceDescriptor.Transient <IControllerActivator, ServiceBasedControllerActivator>());

            //https://docs.microsoft.com/zh-cn/aspnet/core/web-api/?view=aspnetcore-2.1
            services.Configure <ApiBehaviorOptions>(options =>
            {
                //options.SuppressConsumesConstraintForFormFileParameters = true;   //关闭请求multipart推断
                //options.SuppressInferBindingSourcesForParameters = true;          //关闭类型参数推断
                options.SuppressModelStateInvalidFilter = true;   //关闭自动验证对象属性并处理
            });

            //services.AddMvc(options =>
            //{
            //    options.Filters.Add<AuthorizationFilter>();
            //    options.Filters.Add<ActionFilter>();
            //    options.Filters.Add<ExceptionFilter>();
            //}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddControllersWithViews(options =>
            {
                options.Filters.Add <AuthorizationFilter>();
                options.Filters.Add <ActionFilter>();
                options.Filters.Add <ExceptionFilter>();
            }).AddNewtonsoftJson();

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version = "v1",
                    Title   = "MsSystem API"
                });

                //Determine base path for the application.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                //Set the comments path for the swagger json and ui.
                var xmlPath = Path.Combine(basePath, "ProjectNameTemplate.WebApi.xml");
                options.IncludeXmlComments(xmlPath);

                options.OperationFilter <OperationFilter>();
            });

            //TODO  这里修改成需要映射的类库集合
            var autpTypes = Assembly.Load("ProjectNameTemplate.WebApi").GetTypes().ToList();
            //autpTypes.AddRange(Assembly.Load("ProjectNameTemplate.Contract").GetTypes().ToList());
            autpTypes.AddRange(Assembly.Load("ProjectNameTemplate.Core").GetTypes().ToList());
            autpTypes.AddRange(Assembly.Load("ProjectNameTemplate.Application").GetTypes().ToList());
            AutoMapperModule.Initialize(autpTypes);

            //return new AutofacServiceProvider(InitContainerBuilder(services));//第三方IOC接管 core内置DI容器
        }
示例#20
0
 public AccountsServiceTests()
 {
     mapper = AutoMapperModule.CreateMapper();
 }
示例#21
0
        public void MapProfiles_AreValid()
        {
            var cfg = AutoMapperModule.ScanForMapProfiles(new[] { typeof(Startup).Assembly });

            cfg.AssertConfigurationIsValid();
        }
        public void IsValid()
        {
            var configuration = AutoMapperModule.CreateMapperConfiguration <QuestionProfile>();

            configuration.AssertConfigurationIsValid();
        }
示例#23
0
 public ClientServiceTests()
 {
     mapper = AutoMapperModule.CreateMapper();
 }