本文整理汇总了C#中IServiceCollection.AddMvcCore方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddMvcCore方法的具体用法?C# IServiceCollection.AddMvcCore怎么用?C# IServiceCollection.AddMvcCore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddMvcCore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
//Add custom exception filter
options.Filters.Add(typeof(CustomExceptionFilter));
//Convert null responses from Action to a 204
options.OutputFormatters.Add(new HttpNoContentOutputFormatter());
});
//Remove default Camel Casing for JSON
//Option 1:
//.AddJsonOptions(opt =>
//{
// var resolver = opt.SerializerSettings.ContractResolver;
// if (resolver != null)
// {
// var res = resolver as DefaultContractResolver;
// res.NamingStrategy = null;
// }
//});
//Option 2:
services.AddMvcCore().AddJsonFormatters(jsonFormatter =>
{
jsonFormatter.ContractResolver = new DefaultContractResolver();
});
}
示例2: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(Configuration);
// We re-register the Scenarios as an instance singleton here to avoid it being created again due to the
// registration done in Program.Main
services.AddSingleton(Scenarios);
// Common DB services
services.AddSingleton<IRandom, DefaultRandom>();
services.AddSingleton<ApplicationDbSeeder>();
services.AddEntityFrameworkSqlServer()
.AddDbContext<ApplicationDbContext>();
if (Scenarios.Any("Raw") || Scenarios.Any("Dapper"))
{
// TODO: Add support for plugging in different DbProviderFactory implementations via configuration
services.AddSingleton<DbProviderFactory>(SqlClientFactory.Instance);
}
if (Scenarios.Any("Ef"))
{
services.AddScoped<EfDb>();
}
if (Scenarios.Any("Raw"))
{
services.AddScoped<RawDb>();
}
if (Scenarios.Any("Dapper"))
{
services.AddScoped<DapperDb>();
}
if (Scenarios.Any("Fortunes"))
{
services.AddWebEncoders();
}
if (Scenarios.Any("Mvc"))
{
var mvcBuilder = services
.AddMvcCore()
//.AddApplicationPart(typeof(Startup).GetTypeInfo().Assembly)
.AddControllersAsServices();
if (Scenarios.MvcJson)
{
mvcBuilder.AddJsonFormatters();
}
if (Scenarios.MvcViews || Scenarios.Any("MvcDbFortunes"))
{
mvcBuilder
.AddViews()
.AddRazorViewEngine();
}
}
}
示例3: 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.AddApplicationInsightsTelemetry(Configuration);
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
//Swagger additons
services.AddMvcCore()
.AddApiExplorer();
services.AddSwaggerGen();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<BookServiceContext>(options =>
options.UseSqlServer(Configuration["ConnectionString"]));
//options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=BookServiceContext-70e8c6ed-94f8-4d84-97df-d0729ea62482;Trusted_Connection=True;MultipleActiveResultSets=true"));
}
示例4: 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.AddMvcCore()
.AddJsonFormatters()
.AddApiExplorer();
}
示例5: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// Without a call to AddControllersAsServices, this project
// requires ("preserveCompilationContext": true)
services.AddMvcCore()
.AddJsonFormatters()
.AddControllersAsServices(typeof(Startup).GetTypeInfo().Assembly);
}
示例6: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add SmsService.
services.AddServiceFabricService<ISmsService, SmsService>();
// Add framework services.
services.AddMvcCore()
.AddJsonFormatters();
}
示例7: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// Example 1
services
.AddMvcCore()
.AddAuthorization()
.AddFormatterMappings(m => m.SetMediaTypeMappingForFormat("js", new MediaTypeHeaderValue("application/json")))
.AddJsonFormatters(j => j.Formatting = Formatting.Indented);
}
示例8: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddJsonFormatters(json => json.ContractResolver = new CamelCasePropertyNamesContractResolver())
.AddDataAnnotations();
services.AddSingleton<PetRepository>(new PetRepository());
}
示例9: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddApiExplorer()
.AddJsonFormatters();
services.AddEntityFramework()
.AddInMemoryDatabase()
.AddDbContext<VotingContext>(options =>
options.UseInMemoryDatabase());
services.AddSwaggerGen();
}
示例10: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddJsonFormatters()
.AddAuthorization();
services.AddWebEncoders();
services.AddCors();
services.AddTransient<ClaimsPrincipal>(
s => s.GetService<IHttpContextAccessor>().HttpContext.User);
}
示例11: ConfigureServices
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddJsonFormatters();
// Add Autofac
var builder = new ContainerBuilder();
builder.RegisterModule<DefaultModule>();
builder.Populate(services);
var container = builder.Build();
return container.Resolve<IServiceProvider>();
}
示例12: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
var serviceDescription = new ServiceDescriptor(typeof(IPluginService),typeof(WelcomePlugin),ServiceLifetime.Transient);
services
.AddMvcCore()
.AddAuthorization()
.AddFormatterMappings(m => m.SetMediaTypeMappingForFormat("js", new MediaTypeHeaderValue("application/json")))
.AddJsonFormatters(j => j.Formatting = Formatting.Indented)
.Services.Add(serviceDescription);
}
示例13: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
var configBuilder = new ConfigurationBuilder();
configBuilder.AddJsonFile("config.json");
configBuilder.AddEnvironmentVariables();
this.Configuration = configBuilder.Build();
services.AddOptions();
services.Configure<DotkubeOptions>(this.Configuration);
services.AddTransient<IDatabase>((IServiceCollection) => configureRedis());
services.AddDbContext<DataContext>(options => configureDatabase(options));
services.AddMvcCore().AddJsonFormatters();
services.AddCors();
}
示例14: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
KeyVaultHelper keyVaultHelper = new KeyVaultHelper(Configuration);
KeyVaultHelper.GetCert(Configuration);
keyVaultHelper.GetKeyVaultSecretsCerticate();
services.AddSingleton(Configuration);
ConfigureSettings(services);
services.AddCors();
services.AddLogging();
ConfigureMvc(services, LoggerFactory);
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvcCore();
ConfigureMatterPackages(services);
ConfigureSwagger(services);
}
示例15: Configure
public void Configure(IServiceCollection serviceCollection)
{
serviceCollection
.AddMvcCore()
.AddViews()
.AddRazorViewEngine();
serviceCollection.AddScoped<IAssemblyProvider, OrchardMvcAssemblyProvider>();
serviceCollection.AddSingleton<ICompilationService, DefaultRoslynCompilationService>();
serviceCollection.Configure<RazorViewEngineOptions>(options => {
var expander = new ModuleViewLocationExpander();
options.ViewLocationExpanders.Add(expander);
});
}