• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IServiceCollection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IServiceCollection的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection类的具体用法?C# IServiceCollection怎么用?C# IServiceCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IServiceCollection类属于命名空间,在下文中一共展示了IServiceCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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>();
        }
开发者ID:Jarrku,项目名称:Starter-ASPNET5,代码行数:62,代码来源:Startup.cs


示例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");
                    });
            });
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:60,代码来源:Startup.cs


示例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();
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:27,代码来源:Startup.cs


示例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
        }
开发者ID:FishFuzz99,项目名称:.NET-test,代码行数:27,代码来源:Startup.cs


示例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>();
        }
开发者ID:princeppy,项目名称:AspNet5MultipleProject,代码行数:32,代码来源:Startup.cs


示例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>();
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:8,代码来源:Startup.cs


示例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>();
        }
开发者ID:bbs14438,项目名称:MyShuttle.biz,代码行数:30,代码来源:Startup.cs


示例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"));
        }
开发者ID:marcodiniz,项目名称:TinBot,代码行数:8,代码来源:Startup.cs


示例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());
            });
        }
开发者ID:alexandreana,项目名称:MusicStore,代码行数:27,代码来源:StartupNtlmAuthentication.cs


示例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();
                         }
                     );
                 }
             );
        }
开发者ID:serviax,项目名称:learning,代码行数:28,代码来源:Startup.cs


示例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);

        }
开发者ID:sitharus,项目名称:MHUI,代码行数:31,代码来源:Startup.cs


示例12: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            var documentStore = UseInstalledRavenDocumentStore();
            documentStore.Initialize();

            new ServiceConfigurer(documentStore).ConfigureServices(services);
        }
开发者ID:MarkGravestock,项目名称:ReadingListApi,代码行数:7,代码来源:Startup.cs


示例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>();
        }
开发者ID:cedita,项目名称:Cedita.Passman,代码行数:32,代码来源:Startup.cs


示例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>();
 }
开发者ID:bogdanuifalean,项目名称:JuniorMind,代码行数:8,代码来源:Startup.cs


示例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);



        }
开发者ID:Charmatzis,项目名称:IT4GOV,代码行数:32,代码来源:Startup.cs


示例16: 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.
            //cambiar dependiendo los contextos y cadenas
            //de conexión que tengas
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:ShellDBContextConnection"]));


            services.AddScoped<SeedContext>();



            //services.AddEntityFramework()
            //    .AddSqlServer()
            //    .AddDbContext<Context>();


            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            services.AddMvc();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
        }
开发者ID:juxrez,项目名称:NetCore1-ShellWeb,代码行数:31,代码来源:Startup.cs


示例17: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     // Add EF services to the services container.
     services.AddEntityFramework(Configuration)
         .AddSqlServer()
         .AddDbContext<MoBContext>();
 }
开发者ID:LeoLcy,项目名称:MVC6Recipes,代码行数:7,代码来源:Startup.cs


示例18: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     // Configure AtsOption for NLog.Extensions.AzureTableStorage
     services.ConfigureAts(options => {
         options.StorageAccountConnectionString = Configuration["AppSettings:StorageAccountConnectionString"];
     });
 }
开发者ID:Greenliff,项目名称:NLog.Extensions.AzureTableStorage,代码行数:7,代码来源:Startup.cs


示例19: 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);
        }
开发者ID:navarroaxel,项目名称:AspNet5-Template,代码行数:26,代码来源:Startup.cs


示例20: ConfigureServices

 // This method gets called by a runtime.
 // Use this method to add services to the container
 public void ConfigureServices(IServiceCollection services)
 {
     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();
 }
开发者ID:DevinAwe,项目名称:Web-Programming-FA2015,代码行数:9,代码来源:Startup.cs



注:本文中的IServiceCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IServiceContainer类代码示例发布时间:2022-05-24
下一篇:
C# IServiceClient类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap