// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvcCore() .ConfigureApplicationPartManager(m => m.FeatureProviders.Add(new GenericTypeControllerFeatureProvider())) .AddAuthorization() .AddJsonFormatters(); var assemblyName = Assembly.GetExecutingAssembly().FullName; services.AddDbContext <ApiDBContext>(options => { options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"], b => { b.MigrationsAssembly(assemblyName); b.UseRowNumberForPaging(); //兼容 server 2008 分页 }); }); // github.com/aliostad/CacheCow services.AddHttpCachingMvc(); // github.com/dotnetcore/EasyCaching services.AddDefaultInMemoryCache(); services.AddScoped <DbContext, ApiDBContext>(); DependencyConfig.Config(services, Configuration); services.AddCors(); services.AddOData(); services.AddAutoMapper(); services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = Configuration["AppSettings:IdentityServer"]; options.RequireHttpsMetadata = false; options.ApiName = "api"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc() .ConfigureApplicationPartManager(m => m.FeatureProviders.Add(new GenericTypeControllerFeatureProvider())) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddScoped <DbContext, ApiIdEntityDBContext>(); var assemblyName = Assembly.GetExecutingAssembly().FullName; services.AddDbContext <ApiIdEntityDBContext>(options => { options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"], b => { b.MigrationsAssembly(assemblyName); b.UseRowNumberForPaging(); //server 2008 }); }); // github.com/aliostad/CacheCow services.AddHttpCachingMvc(); // github.com/dotnetcore/EasyCaching services.AddDefaultInMemoryCache(); services.AddScoped <DbContext, ApiIdEntityDBContext>(); DependencyConfig.Config(services, Configuration); services.AddCors(); services.AddOData(); services.AddIdentity <SysUser, SysRole>(options => { options.Tokens.ChangePhoneNumberTokenProvider = "Phone"; options.Password.RequiredLength = 8; options.Password.RequiredUniqueChars = 0; options.Password.RequireDigit = false; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; options.Password.RequireNonAlphanumeric = false; options.Lockout.MaxFailedAccessAttempts = 5; options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); }) .AddEntityFrameworkStores <ApiIdEntityDBContext>() .AddDefaultTokenProviders(); var builder = services.AddIdentityServer(options => { options.Events.RaiseErrorEvents = true; options.Events.RaiseInformationEvents = true; options.Events.RaiseFailureEvents = true; options.Events.RaiseSuccessEvents = true; }) .AddInMemoryIdentityResources(IdentityServiceConfig.GetIdentityResources()) .AddInMemoryApiResources(IdentityServiceConfig.GetApiResources()) .AddInMemoryClients(IdentityServiceConfig.GetClients()) .AddProfileService <ProfileService <SysUser> >() .AddAspNetIdentity <SysUser>(); builder.AddDeveloperSigningCredential(filename: "tempkey.rsa"); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilter(GlobalFilters.Filters); DependencyConfig.Config(); log4net.Config.XmlConfigurator.Configure(); var log = log4net.LogManager.GetLogger(typeof(WebApiApplication)); log.Debug("Logging es habilitado"); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); DependencyConfig.Config(); #if (DEBUG) RunInDebugMode(); #else RunInReleaseMode(); #endif }
protected void Application_Start() { DependencyConfig.Config(); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); using (Context DB = new Context()) { try { DB.Database.Delete(); DB.SaveChanges(); } catch (Exception) { } Card card = new Card() { Name = "Name 1", Description = "Description 1" }; for (int i = 0; i < 5; i++) { Category category = new Category() { Name = "Category " + (i + 1) }; DB.Categories.Add(category); DB.SaveChanges(); card.Categories.Add(category); } DB.Cards.Add(card); DB.SaveChanges(); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); //UnityConfig.RegisterComponents(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilter(GlobalFilters.Filters); DependencyConfig.Config(); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); //RouteConfig.RegisterRoutes(RouteTable.Routes); //BundleConfig.RegisterBundles(BundleTable.Bundles); //var container = new Container(); ////container.Register<IDbContext, IocDbContext>(); //container.Register<IDbContext, IocDbContext>(); ////container.Register<IUserService, UserService>(); //container.Register<IRepository<User>, Repository<User>>(); //container.Register<IRepository<UserProfile>, Repository<UserProfile>>(); //container.Verify(); //DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); //GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorDependencyResolver(container); }