本文整理汇总了C#中IServiceCollection.AddWebEncoders方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddWebEncoders方法的具体用法?C# IServiceCollection.AddWebEncoders怎么用?C# IServiceCollection.AddWebEncoders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddWebEncoders方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(
options => options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
services.AddWebEncoders();
services.AddMvc();
}
示例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: AddViewServices
// Internal for testing.
internal static void AddViewServices(IServiceCollection services)
{
services.AddDataProtection();
services.AddAntiforgery();
services.AddWebEncoders();
services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<MvcViewOptions>, MvcViewOptionsSetup>());
//
// View Engine and related infrastructure
//
// The provider is inexpensive to initialize and provides ViewEngines that may require request
// specific services.
services.TryAddScoped<ICompositeViewEngine, CompositeViewEngine>();
// Support for activating ViewDataDictionary
services.TryAddEnumerable(
ServiceDescriptor
.Transient<IControllerPropertyActivator, ViewDataDictionaryControllerPropertyActivator>());
//
// HTML Helper
//
services.TryAddTransient<IHtmlHelper, HtmlHelper>();
services.TryAddTransient(typeof(IHtmlHelper<>), typeof(HtmlHelper<>));
// DefaultHtmlGenerator is pretty much stateless but depends on IUrlHelper, which is scoped.
// Therefore it too is scoped.
services.TryAddScoped<IHtmlGenerator, DefaultHtmlGenerator>();
//
// JSON Helper
//
services.TryAddSingleton<IJsonHelper, JsonHelper>();
services.TryAdd(ServiceDescriptor.Singleton<JsonOutputFormatter>(serviceProvider =>
{
var options = serviceProvider.GetRequiredService<IOptions<MvcJsonOptions>>().Options;
return new JsonOutputFormatter(options.SerializerSettings);
}));
//
// View Components
//
// These do caching so they should stay singleton
services.TryAddSingleton<IViewComponentSelector, DefaultViewComponentSelector>();
services.TryAddSingleton<IViewComponentActivator, DefaultViewComponentActivator>();
services.TryAddSingleton<
IViewComponentDescriptorCollectionProvider,
DefaultViewComponentDescriptorCollectionProvider>();
services.TryAddTransient<IViewComponentDescriptorProvider, DefaultViewComponentDescriptorProvider>();
services.TryAddSingleton<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();
services.TryAddTransient<IViewComponentHelper, DefaultViewComponentHelper>();
}
示例4: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddJsonFormatters()
.AddAuthorization();
services.AddWebEncoders();
services.AddCors();
services.AddTransient<ClaimsPrincipal>(
s => s.GetService<IHttpContextAccessor>().HttpContext.User);
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddWebEncoders();
// Configure CORS
ConfigureCors(services);
// Configure Web API
ConfigureMvc(services);
// Configure DI
ConfigureDI(services);
// Configure Database & EntityFramework
ConfigureDatabase(services);
// Configure Swagger API documentation
ConfigureSwaggerApiDocumentation(services);
}
示例6: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// No scenarios covered by the benchmarks require the HttpContextAccessor so we're replacing it with a
// no-op version to avoid the cost.
services.AddSingleton(typeof(IHttpContextAccessor), typeof(InertHttpContextAccessor));
if (StartupOptions.EnableDbTests)
{
services.AddSingleton<ApplicationDbSeeder>();
// TODO: Add support for plugging in different DbProviderFactory implementations via configuration
services.AddSingleton<DbProviderFactory>(SqlClientFactory.Instance);
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(StartupOptions.ConnectionString));
services.AddWebEncoders();
}
services.AddMvc();
}
示例7: ConfigureServices
// This method gets called by the runtime.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddWebEncoders();
services.AddDataProtection();
services.Configure<Auth0Settings>(Configuration.GetSection("Auth0"));
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
services.Configure<SharedAuthenticationOptions>(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
var settings = Configuration.Get<Auth0Settings>("Auth0");
services.UseAuth0(settings.Domain, settings.ClientId, settings.ClientSecret, settings.RedirectUri, notification =>
{
var identity = notification.AuthenticationTicket.Principal.Identity as ClaimsIdentity;
// Optional: add custom claims.
/*
if (identity.HasClaim(c => c.Type == "name"))
identity.AddClaim(new Claim(ClaimTypes.Name, identity.FindFirst("name").Value));
identity.AddClaim(new Claim("tenant", "12345"));
identity.AddClaim(new Claim("custom-claim", "custom-value"));
*/
// Optional: store tokens in the user object so you can retrieve those later.
/*
if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.AccessToken))
identity.AddClaim(new Claim("access_token", notification.TokenEndpointResponse.AccessToken));
if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.IdToken))
identity.AddClaim(new Claim("id_token", notification.TokenEndpointResponse.IdToken));
if (!String.IsNullOrEmpty(notification.TokenEndpointResponse.RefreshToken))
identity.AddClaim(new Claim("refresh_token", notification.TokenEndpointResponse.RefreshToken));
*/
return Task.FromResult(true);
});
}
示例8: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddInstance<IHostingEnvironment>(_hostingEnvironment);
services.AddInstance<IApplicationEnvironment>(_appEnvironment);
services.AddOptions();
services.AddAuthentication();
services.AddAuthorization(options =>
{
options.AddPolicy("Authenticated", policy => policy.RequireAuthenticatedUser());
});
services.AddElm();
services.ConfigureElm(options =>
{
// options.Path = new PathString("/foo"); // defaults to "/Elm"
options.Filter = (name, level) => level >= LogLevel.Information;
});
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
services.AddMvcCore().AddJsonFormatters();
services.AddSwaggerGen(c =>
{
c.SingleApiVersion(new Info
{
Version = "v1",
Title = "Swashbuckle Sample API",
Description = "A sample API for testing Swashbuckle",
TermsOfService = "Some terms ..."
});
c.DescribeAllEnumsAsStrings();
c.OperationFilter<AssignOperationVendorExtensions>();
});
if (_hostingEnvironment.IsDevelopment())
{
services.ConfigureSwaggerGen(c =>
{
var xmlPath = string.Format(@"{0}\artifacts\bin\WebApplication1\{1}\{2}{3}\WebApplication1.xml",
GetSolutionBasePath(),
_appEnvironment.Configuration,
_appEnvironment.RuntimeFramework.Identifier,
_appEnvironment.RuntimeFramework.Version.ToString().Replace(".", string.Empty));
c.IncludeXmlComments(xmlPath);
var xmlPath2 = string.Format(@"{0}\artifacts\bin\p6.api.animals.v1\{1}\dotnet5.4\p6.api.animals.v1.xml",
GetSolutionBasePath(),
_appEnvironment.Configuration);
c.IncludeXmlComments(xmlPath2);
});
}
services.AddLogging();
services.AddWebEncoders();
services.AddCors();
services.AddCaching(); // Memory Caching stuff
services.AddSession();
// register the global configuration root
services.AddSingleton<IConfigurationRoot, GlobalConfigurationRoot>();
services.Configure<CassandraConfig>(Configuration.GetSection(CassandraConfig.WellKnown_SectionName));
// Add application services.
// Do this before we do a BuildServiceProvider because some downstream autofac modules need the librarymanager.
ILibraryManager libraryManager = null;
libraryManager = services.GetService<ILibraryManager>();
TypeGlobals.LibraryManager = libraryManager;
services.AddSingleton<IFilterProvider, Pingo.Core.Providers.OptOutOptInFilterProvider>();
services.AddTransient<ClaimsPrincipal>(
s => s.GetService<IHttpContextAccessor>().HttpContext.User);
services.Configure<IdentityOptions>(options =>
{
options.Cookies.ApplicationCookie.LoginPath = new Microsoft.AspNet.Http.PathString("/Identity/Account/Login");
options.Cookies.ApplicationCookie.LogoutPath = new Microsoft.AspNet.Http.PathString("/Identity/Account/LogOff");
});
services.AddAllConfigureServicesRegistrants(Configuration);
// autofac auto registration
services.AddDependencies();
var serviceProvider = services.BuildServiceProvider(Configuration);
// Setup the PingoGlobal static . Easier to use that trying to resolve everytime.
//.........这里部分代码省略.........
示例9: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddWebEncoders();
services.AddDataProtection();
services.AddIdentityServer(options =>
{
options.SigningCertificate = _environment.LoadSigningCert();
options.AuthenticationOptions.PrimaryAuthenticationScheme = CookieAuthenticationScheme;
})
.AddInMemoryClients(_clients)
.AddInMemoryScopes(_scopes)
.AddInMemoryUsers(_users);
}
示例10: ConfigureDefaultServices
private static void ConfigureDefaultServices(IServiceCollection services)
{
services.AddDataProtection();
services.AddCors();
services.AddAuthorization();
services.AddWebEncoders();
}
示例11: ConfigureDefaultServices
private static void ConfigureDefaultServices(IServiceCollection services)
{
services.AddOptions();
services.AddDataProtection();
services.AddRouting();
services.AddCors();
services.AddAuthorization();
services.AddWebEncoders();
services.Configure<RouteOptions>(
routeOptions => routeOptions.ConstraintMap.Add("exists", typeof(KnownRouteValueConstraint)));
}
示例12: 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"))
{
services.AddSingleton<DbProviderFactory>((provider) => {
var settings = provider.GetRequiredService<IOptions<AppSettings>>().Value;
if (settings.Database == DatabaseServer.PostgreSql)
{
return NpgsqlFactory.Instance;
}
else
{
return 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"))
{
var settings = new TextEncoderSettings(UnicodeRanges.BasicLatin, UnicodeRanges.Katakana, UnicodeRanges.Hiragana);
settings.AllowCharacter('\u2014'); // allow EM DASH through
services.AddWebEncoders((options) =>
{
options.TextEncoderSettings = settings;
});
}
if (Scenarios.Any("Mvc"))
{
var mvcBuilder = services
.AddMvcCore()
//.AddApplicationPart(typeof(Startup).GetTypeInfo().Assembly)
.AddControllersAsServices();
if (Scenarios.MvcJson || Scenarios.Any("MvcDbSingle") || Scenarios.Any("MvcDbMulti"))
{
mvcBuilder.AddJsonFormatters();
}
if (Scenarios.MvcViews || Scenarios.Any("MvcDbFortunes"))
{
mvcBuilder
.AddViews()
.AddRazorViewEngine();
}
}
}
示例13: AddViewServices
// Internal for testing.
internal static void AddViewServices(IServiceCollection services)
{
services.AddDataProtection();
services.AddAntiforgery();
services.AddWebEncoders();
services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<MvcViewOptions>, MvcViewOptionsSetup>());
services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, TempDataMvcOptionsSetup>());
//
// View Engine and related infrastructure
//
services.TryAddSingleton<ICompositeViewEngine, CompositeViewEngine>();
services.TryAddSingleton<ViewResultExecutor>();
services.TryAddSingleton<PartialViewResultExecutor>();
// Support for activating ViewDataDictionary
services.TryAddEnumerable(
ServiceDescriptor
.Transient<IControllerPropertyActivator, ViewDataDictionaryControllerPropertyActivator>());
//
// HTML Helper
//
services.TryAddTransient<IHtmlHelper, HtmlHelper>();
services.TryAddTransient(typeof(IHtmlHelper<>), typeof(HtmlHelper<>));
services.TryAddSingleton<IHtmlGenerator, DefaultHtmlGenerator>();
//
// JSON Helper
//
services.TryAddSingleton<IJsonHelper, JsonHelper>();
services.TryAdd(ServiceDescriptor.Singleton<JsonOutputFormatter>(serviceProvider =>
{
var options = serviceProvider.GetRequiredService<IOptions<MvcJsonOptions>>().Value;
var charPool = serviceProvider.GetRequiredService<ArrayPool<char>>();
return new JsonOutputFormatter(options.SerializerSettings, charPool);
}));
//
// View Components
//
// These do caching so they should stay singleton
services.TryAddSingleton<IViewComponentSelector, DefaultViewComponentSelector>();
services.TryAddSingleton<IViewComponentActivator, DefaultViewComponentActivator>();
services.TryAddSingleton<
IViewComponentDescriptorCollectionProvider,
DefaultViewComponentDescriptorCollectionProvider>();
services.TryAddTransient<IViewComponentDescriptorProvider, DefaultViewComponentDescriptorProvider>();
services.TryAddSingleton<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();
services.TryAddTransient<IViewComponentHelper, DefaultViewComponentHelper>();
//
// Temp Data
//
// This does caching so it should stay singleton
services.TryAddSingleton<ITempDataProvider, SessionStateTempDataProvider>();
//
// Antiforgery
//
services.TryAddSingleton<ValidateAntiforgeryTokenAuthorizationFilter>();
services.TryAddSingleton<AutoValidateAntiforgeryTokenAuthorizationFilter>();
// These are stateless so their lifetime isn't really important.
services.TryAddSingleton<ITempDataDictionaryFactory, TempDataDictionaryFactory>();
services.TryAddSingleton<SaveTempDataFilter>();
services.TryAddSingleton(ArrayPool<ViewBufferValue>.Shared);
services.TryAddScoped<IViewBufferScope, MemoryPoolViewBufferScope>();
}