当前位置: 首页>>代码示例>>C#>>正文


C# IServiceCollection.Configure方法代码示例

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


在下文中一共展示了IServiceCollection.Configure方法的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)
        {
            
            // you can use either json or xml to maintain your navigation map we provide examples of each navigation.xml and 
            // navigation.json in the root of this project
            // you can override the name of the file used with AppSettings:NavigationXmlFileName or AppSettings:NavigationJsonFileName in config.json
            // the file must live in the root of the web project code not in wwwroot

            // it is arguable which is easier for humans to read and maintain, myself I think for something like a navigation tree
            // that could get large xml is easier to work with and not make mistakes. in json one missing or extra comma can break it
            // granted xml can be broken by typos too but the end tags make it easier to keep track of where you are imho (JA)
            //services.TryAddScoped<INavigationTreeBuilder, JsonNavigationTreeBuilder>();
            //services.TryAddScoped<INavigationTreeBuilder, HardCodedNavigationTreeBuilder>();
            services.TryAddScoped<INavigationTreeBuilder, XmlNavigationTreeBuilder>();
            services.TryAddScoped<INodeUrlPrefixProvider, DefaultNodeUrlPrefixProvider>();
            services.TryAddScoped<INavigationNodePermissionResolver, NavigationNodePermissionResolver>();
            services.Configure<NavigationOptions>(Configuration.GetSection("NavigationOptions"));
            services.Configure<DistributedCacheNavigationTreeBuilderOptions>(Configuration.GetSection("DistributedCacheNavigationTreeBuilderOptions"));
            services.Configure<MemoryCacheNavigationTreeBuilderOptions>(Configuration.GetSection("MemoryCacheNavigationTreeBuilderOptions"));
            services.TryAddScoped<INavigationCacheKeyResolver, DefaultNavigationCacheKeyResolver>();

            // Add MVC services to the services container.
            services.AddMvc();

            
        }
开发者ID:lespera,项目名称:cloudscribe.Web.Navigation,代码行数:27,代码来源:Startup.cs

示例2: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services) {
            // Add Application settings to the services container.
            services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));

            // Add EF 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>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            // Configure the options for the authentication middleware.
            // You can add options for Google, Twitter and other middleware as shown below.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            services.Configure<FacebookAuthenticationOptions>(options => {
                options.AppId = Configuration["Authentication:Facebook:AppId"];
                options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
            });

            services.Configure<MicrosoftAccountAuthenticationOptions>(options => {
                options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
                options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
            });

            // 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();
        }
开发者ID:beginor,项目名称:practice,代码行数:36,代码来源:Startup.cs

示例3: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddCaching();
            services.AddSession();

            services.AddSwaggerGen();

            services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure<MvcOptions>(options =>
            {
                //options.RespectBrowserAcceptHeader = true;
            });
            services.AddEntityFramework()
                .AddInMemoryDatabase()
                .AddDbContext<ApplicationDbContext>(options => { options.UseInMemoryDatabase(); });

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

            services.AddTransient<ApplicationUserManager>();
            services.AddTransient<ApplicationSignInManager>();
            services.AddTransient<IUserImageProvider, GravatarProvider>();

            services.AddAuthentication();

            // https://github.com/aspnet/Entropy/blob/dev/samples/Logging.Elm/Startup.cs
            services.AddElm();
        }
开发者ID:CWISoftware,项目名称:accounts,代码行数:32,代码来源:Startup.cs

示例4: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        { 

            // Configure the options for the authentication middleware.
            // You can add options for Google, Twitter and other middleware as shown below.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            services.Configure<FacebookAuthenticationOptions>(options =>
            {
                options.AppId = Configuration["Authentication:Facebook:AppId"];
                options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
            });

            services.Configure<MicrosoftAccountAuthenticationOptions>(options =>
            {
                options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
                options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
            });

            // 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();
        }
开发者ID:blake-mobileux,项目名称:HelloWorldTodoList,代码行数:26,代码来源:Startup.cs

示例5: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMultitenancy<AppTenant, CachingAppTenantResolver>();

            // Add framework services.
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

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

            services.AddOptions();

            services.AddMvc();
             
            services.Configure<RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new TenantViewLocationExpander());
            });

            services.Configure<MultitenancyOptions>(Configuration.GetSection("Multitenancy"));

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
        }
开发者ID:3arlN3t,项目名称:saaskit,代码行数:30,代码来源:Startup.cs

示例6: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.Configure<AppSettings>(_configuration.GetSection("AppSettings"));
     services.Configure<DomainSettings>(_configuration.GetSection("Data:DbConnection"));
     services.AddScoped<IBritishProverbsContext, BritishProverbsContext>();
     services.AddMvc();
 }
开发者ID:british-proverbs,项目名称:british-proverbs-mvc-6,代码行数:7,代码来源:Startup.cs

示例7: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Read settings from config
            services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure<DevelopmentSettings>(Configuration.GetSection("DevelopmentSettings"));

            // Add Entity Framework services to the services container.
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<DataContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            // Add Identity services with custom UserStore and RoleStore with EF6 support to the services container.
            services.AddIdentity<User, Role>(o => {
                // configure identity options
                o.Password.RequireDigit = false;
                o.Password.RequireLowercase = false;
                o.Password.RequireUppercase = false;
                o.Password.RequireNonLetterOrDigit = false;
                o.Password.RequiredLength = 6;
            })
            .AddEntityFrameworkStores<DataContext, int>()
            .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();

            // Add application services.
            AddApplicationServices(services);

            services.RegisterDataTables();
        }
开发者ID:Supermakaka,项目名称:mvc6,代码行数:36,代码来源: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.AddCaching();
            services.AddSession();

            // Configuration
            services.Configure<EncryptionConfig>(Configuration.GetSection("Encryption"));
            services.Configure<EmailConfig>(Configuration.GetSection("Email"));
            services.Configure<RedisConfig>(Configuration.GetSection("Redis"));

            // Dependency Injection
            services.AddSingleton<IRedisService, RedisService>();
            services.AddSingleton<IEncryptionService, BasicEncryption>();
            services.AddSingleton<ISchedulerService, SchedulerService>();
            services.AddSingleton<IEmailService, EmailService>();
            services.AddTransient<IMojangService, MojangService>();
            services.AddTransient<IUserService, UserService>();
            services.AddTransient<IUsernameService, UsernameService>();

            // Automapper
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperProfile());
            });
            services.AddSingleton(sp => config.CreateMapper());
        }
开发者ID:AMerkuri,项目名称:MCNotifier,代码行数:29,代码来源:Startup.cs

示例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.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<SiteContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

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

			services.AddOptions();

			services.Configure<BraintreeSettings>(Configuration.GetSection("AppSettings:Braintree"));
			services.Configure<ConstantContactSettings>(Configuration.GetSection("AppSettings:ConstantContact"));

			services.AddMvc();
			services.AddCaching();
			services.AddSession();

			services.ConfigureRouting(opts =>
			{
				opts.AppendTrailingSlash = false;
				opts.LowercaseUrls = true;
			});

			// Add application services.
			services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
			services.AddScoped<IBookstoreRepository, EFBookstoreRepository>();
        }
开发者ID:malevolence,项目名称:ContosoBooks,代码行数:33,代码来源:Startup.cs

示例10: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var useInMemoryStore = !_Platform.IsRunningOnWindows || _Platform.IsRunningOnMono || _Platform.IsRunningOnNanoServer;

            services.ConfigureDataContext(Configuration, useInMemoryStore);

            // Register dependencies
            services.ConfigureDependencies(Configuration);

            // Add Entity Framework services to the services container.
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<MyHealthContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            // Add MVC services to the services container.
            services.AddMvc();

            services.AddOptions();
            services.Configure<DefaultUser>(Configuration.GetSection("DefaultUser"));
            services.Configure<Office365Options>(Configuration.GetSection("Data:Office365"));
            services.AddSingleton<IMemoryCache, MemoryCache>();

            // 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:geekpivot,项目名称:HealthClinic.biz,代码行数:28,代码来源:Startup.cs

示例11: 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.AddScoped<ImdbContext>();

			services.AddOptions();

			services.Configure<ImdbOptions>(_configuration.GetSection("Imdb"));
			
			services.AddMvc();

			services.Configure<MvcOptions>(options =>
			{
				options.OutputFormatters.Clear();
				options.InputFormatters.Clear();

				var jss = new JsonSerializerSettings
				{
					Formatting = Formatting.Indented,
					ContractResolver = new CamelCasePropertyNamesContractResolver()
				};
				jss.Converters.Add(new StringEnumConverter());

				options.InputFormatters.Add(new JsonInputFormatter(jss));
				options.OutputFormatters.Add(new JsonOutputFormatter(jss));

				options.InputFormatters.Add(new XmlSerializerInputFormatter());
				options.OutputFormatters.Add(new XmlSerializerOutputFormatter());
			});
		}
开发者ID:ProgramUtvikling,项目名称:mvckurs-jan-2016,代码行数:31,代码来源:Startup.cs

示例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.AddApplicationInsightsTelemetry(Configuration);
            services.Configure<IISOptions>(options =>
            {

            });

            services.Configure<DapperOptions>(options =>
            {
                options.ConnectionString = Configuration.GetConnectionString("DapperConnection");
            });

            //api authorized middleware
            services.AddApiAuthorized(options =>
            {
                options.EncryptKey = Configuration.GetSection("ApiKey")["EncryptKey"];
                options.ExpiredSecond = Convert.ToInt32(Configuration.GetSection("ApiKey")["ExpiredSecond"]);
            });


            services.AddMvc();

            services.AddSingleton<DapperHelper>();
        }
开发者ID:hwqdt,项目名称:Demos,代码行数:27,代码来源:Startup.cs

示例13: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure<MySettings>(_configuration);
            services.Configure<OtherSettings>(_configuration.GetSection("otherSettings"));

            services.AddScoped<MyClass>();
        }
开发者ID:jeffogata,项目名称:aspnet-configuration-04-cli,代码行数:8,代码来源:Startup.cs

示例14: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddTransient<VsoFactory>();
            services.Configure<TfsServer>(Configuration.GetConfigurationSection("TfsServer"));
            services.Configure<AppSettings>(Configuration.GetConfigurationSection("AppSettings"));
        }
开发者ID:Lambda3,项目名称:tfspanel,代码行数:8,代码来源:Startup.cs

示例15: ConfigureOptionsServices

        /// <summary>
        /// Configures the settings by binding the contents of the config.json file to the specified Plain Old CLR 
        /// Objects (POCO) and adding <see cref="IOptions{}"/> objects to the services collection.
        /// </summary>
        /// <param name="services">The services collection or IoC container.</param>
        /// <param name="configuration">Gets or sets the application configuration, where key value pair settings are 
        /// stored.</param>
        private static void ConfigureOptionsServices(IServiceCollection services, IConfiguration configuration)
        {
            // Adds IOptions<AppSettings> to the services container.
            services.Configure<AppSettings>(configuration.GetSection(nameof(AppSettings)));

            // Adds IOptions<CacheProfileSettings> to the services container.
            services.Configure<CacheProfileSettings>(configuration.GetSection(nameof(CacheProfileSettings)));
        }
开发者ID:modulexcite,项目名称:ASP.NET-MVC-Boilerplate,代码行数:15,代码来源:Startup.Options.cs


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