本文整理汇总了C#中IServiceCollection.AddMvc方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddMvc方法的具体用法?C# IServiceCollection.AddMvc怎么用?C# IServiceCollection.AddMvc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddMvc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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["Data:DefaultConnection:ConnectionString"]));
var connection = @"Server=DESKTOP-2N2TC81;Database=NeedleWork2016;Trusted_Connection=True;";
//var connection = @"Data Source=10.10.200.62;Initial Catalog=NeedleWork2016;Persist Security Info=True;User ID=needlework2016;Password=Qwerty1!";
services.AddEntityFramework()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connection));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.AddMvc();
services.AddMvc(options =>
{
options.Filters.Add(new ConvertToPdfFilterAttribute());
options.Filters.Add(new CultureAttribute());
});
}
示例2: 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()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]))
.AddDbContext<TriviaDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
});
}
示例3: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var path = _app.ApplicationBasePath;
var config = new ConfigurationBuilder()
.AddJsonFile($"{path}/config.json")
.Build();
string typeName = config.Get<string>("RepositoryType");
services.AddSingleton(typeof(IBoilerRepository), Type.GetType(typeName));
object repoInstance = Activator.CreateInstance(Type.GetType(typeName));
IBoilerRepository repo = repoInstance as IBoilerRepository;
services.AddInstance(typeof(IBoilerRepository), repo);
TimerAdapter timer = new TimerAdapter(0, 500);
BoilerStatusRepository db = new BoilerStatusRepository();
services.AddInstance(typeof(BoilerMonitor), new BoilerMonitor(repo, timer, db));
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
// 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();
return services.BuildServiceProvider();
}
示例4: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// only allow authenticated users
var defaultPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
services.AddMvc(setup =>
{
setup.Filters.Add(new AuthorizeFilter(defaultPolicy));
});
services.AddAuthorization(options =>
{
// inline policies
options.AddPolicy("SalesOnly", policy =>
{
policy.RequireClaim("department", "sales");
});
options.AddPolicy("SalesSenior", policy =>
{
policy.RequireClaim("department", "sales");
policy.RequireClaim("status", "senior");
});
});
// 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, ApplicationRole>()
.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>();
}
示例5: 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)
{
services.AddMvc();
services.AddCaching();
services.AddSession();
services
.AddEntityFramework()
.AddSqlServer()
.AddDbContext<OrderContext>(options =>
options.UseSqlServer());
services.AddMvc();
}
示例6: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.ConfigureCors(options =>
{
options.AddPolicy("AllowSpecificOrigins",
builder => builder.WithOrigins("http://localhost:15831")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
.Build());
});
//services.AddAuthorization(options =>
//{
// options.AddPolicy("GetTokenClaims",
// policy => policy.Requirements.Add(new Karama.Resources.Aspnet5.Controllers.GetTokenClaimsRequirement()));
//});
services.AddAuthorization(options =>
{
options.AddPolicy("GetTokenClaims",
policy => policy.RequireClaim("role", "gettokenclaims"));
});
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();
}
示例7: 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.AddInstance<IMulaRepository>(new MulaRepository());
}
示例8: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFrameworkSqlServer()
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:ConnectionString"]));
services
.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
options.Password.RequiredLength = 6;
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Lockout.AllowedForNewUsers = false;
options.SignIn.RequireConfirmedEmail = false;
options.SignIn.RequireConfirmedPhoneNumber = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddUserStore<MyUserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, string>>()
.AddRoleStore<MyRoleStore<ApplicationRole, ApplicationDbContext, string>>();
// Add framework services.
services.AddMvc();
}
示例9: 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"));
}
示例10: ConfigureServices
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddEntityFramework()
.AddSqlServer()
.AddDbContext<TemplateContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddMvc().Configure<MvcOptions>(options =>
{
// Support Camelcasing in MVC API Controllers
int position = options.OutputFormatters.ToList().FindIndex(f => f is JsonOutputFormatter);
var formatter = new JsonOutputFormatter()
{
SerializerSettings = new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
}
};
options.OutputFormatters.Insert(position, formatter);
});
ConfigureRepositories(services);
}
示例11: 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>();
}
示例12: 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>();
}
示例13: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
#region Token Bearer
services.AddJwtAuthentication(Path.Combine(_env.ContentRootPath, "./Security"), "RsaKey.json", "noobs", "http://leadisjourney.fr");
#endregion
services.AddNHibernate(Configuration.GetConnectionString("type"), Configuration.GetConnectionString("DefaultConnection"));
// Add framework services.
services.AddMvc();
services.AddCors(option => option.AddPolicy("AllowAll", p =>
{
p.AllowAnyOrigin();
p.AllowCredentials();
p.AllowAnyMethod();
p.AllowAnyHeader();
}));
// Adding ioc Autofac
var containerBuilder = new ContainerBuilder();
containerBuilder.Populate(services);
containerBuilder.RegisterModule<GlobalRegistration>();
var container = containerBuilder.Build();
return container.Resolve<IServiceProvider>();
}
示例14: ConfigureServices
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container
services.AddMvc();
services.Configure<RouteOptions>(routeOptions => routeOptions.LowercaseUrls = true);
}
示例15: 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.AddTransient(typeof(IToolsCatalogService), typeof(ToolsCatalogService));
}