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


C# IServiceCollection.AddMvcCore方法代码示例

本文整理汇总了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();
            });

        }
开发者ID:DanWahlin,项目名称:ASP.NET5Demos,代码行数:30,代码来源:Startup.cs

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

示例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"));
        }
开发者ID:jlrc,项目名称:BookService-Core,代码行数:34,代码来源: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)
 {
     // Add framework services.
     services.AddMvcCore()
         .AddJsonFormatters()
         .AddApiExplorer();
 }
开发者ID:TerribleDev,项目名称:api.tparnell.io,代码行数:8,代码来源:Startup.cs

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

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

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

示例8: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddMvcCore()
                .AddJsonFormatters(json => json.ContractResolver = new CamelCasePropertyNamesContractResolver())
                .AddDataAnnotations();

            services.AddSingleton<PetRepository>(new PetRepository());
        }
开发者ID:tuespetre,项目名称:mvc-sandbox,代码行数:9,代码来源:Startup.cs

示例9: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvcCore()
                    .AddApiExplorer()
                    .AddJsonFormatters();

            services.AddEntityFramework()
                    .AddInMemoryDatabase()
                    .AddDbContext<VotingContext>(options =>
                            options.UseInMemoryDatabase());

            services.AddSwaggerGen();
        }
开发者ID:paulopez78,项目名称:voting,代码行数:13,代码来源:StartUp.cs

示例10: ConfigureServices

        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddMvcCore()
                .AddJsonFormatters()
                .AddAuthorization();

            services.AddWebEncoders();
            services.AddCors();

            services.AddTransient<ClaimsPrincipal>(
                s => s.GetService<IHttpContextAccessor>().HttpContext.User);
        }
开发者ID:thirkcircus,项目名称:IdentityServer4.Samples,代码行数:13,代码来源:Startup.cs

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

示例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);
            
            
        }
开发者ID:ardacetinkaya,项目名称:aspnet.core-Samples,代码行数:14,代码来源:Startup.cs

示例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();
        }
开发者ID:colemickens,项目名称:dotkube_____old,代码行数:15,代码来源: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)
 {
     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);
 }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:17,代码来源:Startup.cs

示例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);
            });
        }
开发者ID:jp311,项目名称:Brochard,代码行数:16,代码来源:MvcModule.cs


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