本文整理汇总了C#中IServiceCollection类的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection类的具体用法?C# IServiceCollection怎么用?C# IServiceCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IServiceCollection类属于命名空间,在下文中一共展示了IServiceCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// dependency injection containers
public void ConfigureServices(IServiceCollection services)
{
// addjsonoptions -> dataobjecten naar camelCase ipv .net standaard wanneer men ze parsed, gemakkelijker voor js
services.AddMvc(/*config =>
{
//hier kan men forcen voor naar https versie van site te gaan, werkt momenteel niet, geen certificaten
config.Filters.Add(new RequireHttpsAttribute());
}*/)
.AddJsonOptions(opt =>
{
opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
services.AddLogging();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<CatalogusContext>();
services.AddIdentity<Gebruiker, IdentityRole>(config =>
{
//todo requirements voor login
config.User.RequireUniqueEmail = true;
config.Password.RequiredLength = 8;
//route gebruikers naar loginpagina als ze afgeschermde url proberen te bereiken
config.Cookies.ApplicationCookie.LoginPath = "/Auth/Login";
//dit zorgt ervoor dat api calls niet naar loginpagina gereroute worden maar een echte error teruggeven aan de api caller
config.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents()
{
OnRedirectToLogin = ctx =>
{
if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == (int)HttpStatusCode.OK)
{
//kijkt of er api call wordt gedaan en geeft dan correcte httpstatus terug, zodat de caller weet dat hij niet genoeg rechten heeft
ctx.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
}
else
{
//Standaard gedrag
ctx.Response.Redirect(ctx.RedirectUri);
}
return Task.FromResult(0);
}
};
})
.AddEntityFrameworkStores<CatalogusContext>();
//Moet maar1x opgeroept worden, snellere garbage collect
services.AddTransient<CatalogusContextSeedData>();
services.AddScoped<ICatalogusRepository, CatalogusRepository>();
//eigen services toevoegen , bijv mail
//momenteel debugMail ingevoerd
services.AddScoped<IMailService, DebugMailService>();
}
示例2: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<CorsOptions>(options =>
{
options.AddPolicy(
"AllowAnySimpleRequest",
builder =>
{
builder.AllowAnyOrigin()
.WithMethods("GET", "POST", "HEAD");
});
options.AddPolicy(
"AllowSpecificOrigin",
builder =>
{
builder.WithOrigins("http://example.com");
});
options.AddPolicy(
"WithCredentials",
builder =>
{
builder.AllowCredentials()
.WithOrigins("http://example.com");
});
options.AddPolicy(
"WithCredentialsAnyOrigin",
builder =>
{
builder.AllowCredentials()
.AllowAnyOrigin()
.AllowAnyHeader()
.WithMethods("PUT", "POST")
.WithExposedHeaders("exposed1", "exposed2");
});
options.AddPolicy(
"AllowAll",
builder =>
{
builder.AllowCredentials()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowAnyOrigin();
});
options.AddPolicy(
"Allow example.com",
builder =>
{
builder.AllowCredentials()
.AllowAnyMethod()
.AllowAnyHeader()
.WithOrigins("http://example.com");
});
});
}
示例3: ConfigureServices
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.ConfigureRouting(
routeOptions => routeOptions.ConstraintMap.Add(
"IsbnDigitScheme10",
typeof(IsbnDigitScheme10Constraint)));
services.ConfigureRouting(
routeOptions => routeOptions.ConstraintMap.Add(
"IsbnDigitScheme13",
typeof(IsbnDigitScheme10Constraint)));
// Update an existing constraint from ConstraintMap for test purpose.
services.ConfigureRouting(
routeOptions =>
{
if (routeOptions.ConstraintMap.ContainsKey("IsbnDigitScheme13"))
{
routeOptions.ConstraintMap["IsbnDigitScheme13"] =
typeof(IsbnDigitScheme13Constraint);
}
});
// Add MVC services to the services container
services.AddMvc();
}
示例4: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddJsonOptions(opt =>
{
opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // makes api results use camel case
});
services.AddLogging();
services.AddScoped<CoordService>();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<WorldContext>();
services.AddTransient<WorldContextSeedData>();
services.AddScoped<IWorldRepository, WorldRepository>();
#if DEBUG
services.AddScoped<IMailService, DebugMailService>();
#else
services.AddScoped<IMailService, MailService>(); // or something like that
#endif
}
示例5: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<DomainModelSqliteContext>();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<DomainModelMsSqlServerContext>();
JsonOutputFormatter jsonOutputFormatter = new JsonOutputFormatter
{
SerializerSettings = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}
};
services.AddMvc(
options =>
{
options.OutputFormatters.Clear();
options.OutputFormatters.Insert(0, jsonOutputFormatter);
}
);
// Use a SQLite database
services.AddScoped<IDataAccessProvider, DataAccessSqliteProvider>();
// Use a MS SQL Server database
//services.AddScoped<IDataAccessProvider, DataAccessMsSqlServerProvider>();
}
示例6: ConfigureServices
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container
services.AddMvc();
services.AddSingleton<ICompilerCache, CustomCompilerCache>();
services.AddSingleton<CompilerCacheInitialiedService>();
}
示例7: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.ConfigureDataContext(Configuration);
// Register MyShuttle dependencies
services.ConfigureDependencies();
//Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<MyShuttleContext>()
.AddDefaultTokenProviders();
CookieServiceCollectionExtensions.ConfigureCookieAuthentication(services, options =>
{
options.LoginPath = new Microsoft.AspNet.Http.PathString("/Carrier/Login");
});
// Add MVC services to the services container
services.AddMvc();
services
.AddSignalR(options =>
{
options.Hubs.EnableDetailedErrors = true;
});
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
}
示例8: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.Configure<AppConfig>(Configuration.GetSection("AppConfig"));
}
示例9: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// Add EF services to the services container
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration.Get("Data:DefaultConnection:ConnectionString")));
// Add MVC services to the services container
services.AddMvc();
//Add all SignalR related services to IoC.
services.AddSignalR();
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Add session related services.
services.AddCaching();
services.AddSession();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
{
options.AddPolicy("ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build());
});
}
示例10: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddCors
(
options =>
{
options.AddPolicy
(
"AllowSpecificDomains",
builder =>
{
var allowedDomains = new[] { "http://localhost:3000", "https://localhost:5000" };
//Load it
builder
.WithOrigins(allowedDomains)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
}
);
}
);
}
示例11: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<ApplicationDbContext>();
services.AddTransient<ApplicationDbContext, ApplicationDbContext>();
services.AddIdentity<ApplicationUser, IdentityRole>(opt =>
{
opt.Password.RequireDigit = false;
opt.Password.RequireNonLetterOrDigit = false;
opt.Password.RequireUppercase = false;
opt.Password.RequireLowercase = false;
opt.User.AllowedUserNameCharacters = opt.User.AllowedUserNameCharacters + '+';
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddSingleton(CreateJSEngine);
}
示例12: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
var documentStore = UseInstalledRavenDocumentStore();
documentStore.Initialize();
new ServiceConfigurer(documentStore).ConfigureServices(services);
}
示例13: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add Entity Framework services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>(m =>
// Configure Identity
{
m.Password.RequireUppercase = false;
m.Password.RequireLowercase = false;
m.Password.RequireNonLetterOrDigit = false;
m.Password.RequireDigit = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Add MVC services to the services container.
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
// Register application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
示例14: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddSingleton<ITodoRepository, TodoRepository>();
services.AddSingleton<TaskManagerRepository>();
}
示例15: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
var cert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "idsrv4test.pfx"), "idsrv3test");
var builder = services.AddIdentityServer(options =>
{
options.SigningCertificate = cert;
});
builder.AddInMemoryClients(Clients.Get());
builder.AddInMemoryScopes(Scopes.Get());
builder.AddInMemoryUsers(Users.Get());
builder.AddCustomGrantValidator<CustomGrantValidator>();
// for the UI
services
.AddMvc()
.AddRazorOptions(razor =>
{
razor.ViewLocationExpanders.Add(new CustomViewLocationExpander());
});
services.AddTransient<UI.Login.LoginService>();
services.AddTransient<UI.SignUp.SignUpService>();
services.AddTransient<ISmsSender, MessageServices>();
services.Configure<ASPmsSercetCredentials>(Configuration);
}