Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void   ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.Configure <ApiBehaviorOptions>(opt =>
            {
                opt.SuppressModelStateInvalidFilter = true;
            });

            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MappingProfile());
            });

            var mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            MediatRRegistration.RegisterMediatR(services);
            RepositoryRegistration.RegisterRepo(services);
            ServicesRegistration.RegisterService(services);

            services.AddTransient <IUserStore <ApplicationUser>, UserStore>();
            services.AddTransient <IRoleStore <ApplicationRole>, RoleStore>();
            services.AddIdentity <ApplicationUser, ApplicationRole>()
            .AddDefaultTokenProviders();
            services.AddControllersWithViews();
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MappingProfile());
            });

            var mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);
            MediatRRegistration.RegisterMediatR(services);
            RepositoryRegistration.RegisterRepo(services);
            ServicesRegistration.RegisterService(services);
            services.AddScoped <IUnitOfWork, UnitOfWork>();



            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.IdleTimeout        = TimeSpan.FromSeconds(10);
                options.Cookie.HttpOnly    = true;
                options.Cookie.IsEssential = true;
            });
            services.AddControllersWithViews();
        }
Beispiel #3
0
        public static void Register(HttpConfiguration config)
        {
            // Web API 配置和服务
            var container = new Castle.Windsor.WindsorContainer();

            ServicesRegistration.Register(container);
            config.DependencyResolver = new CastleWindsorResolver(container);

            // 注册MessageHandler,作用全局。
            config.MessageHandlers.Add(new MyGlobalMessageHandler());

            // Web API 路由
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi2",
                routeTemplate: "api/MethodOverride/{id}",
                defaults: new { controller = "MethodOverride", id = RouteParameter.Optional },
                constraints: null,
                handler: new MethodOverrideHandler(config)
                );

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Routes.MapHttpRoute(
                name: "DefaultApi3",
                routeTemplate: "api/{controller}/{action}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Filters.Add(new GlobalEffectFilterAttribute());
        }
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <EcommerceContext>(options => options.UseSqlServer(Configuration.GetConnectionString("EcommerceDataBase")));
     services.AddControllers().AddNewtonsoftJson(s => s.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());
     ServicesRegistration.AddRegistration(services);
 }