本文整理汇总了C#中IServiceProvider.GetServices方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.GetServices方法的具体用法?C# IServiceProvider.GetServices怎么用?C# IServiceProvider.GetServices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceProvider
的用法示例。
在下文中一共展示了IServiceProvider.GetServices方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public async Task Invoke(HttpContext context, IServiceProvider serviceProvider)
{
#region IRunOnEachRequest
var befores = serviceProvider.GetServices<IRunOnEachRequest>();
foreach (var cmd in befores)
{
cmd.Execute();
}
#endregion
#region IRunOnEachResponse
Func<object, Task> iRunOnResponseStarted = ctx => RunWhenReponseStarts(serviceProvider);
context.Response.OnStarting(iRunOnResponseStarted, context);
#endregion
#region IRunAfterEachResponse
Func<object, Task> iRunOnResponseCompleted = ctx => RunWhenReponseCompletes(serviceProvider);
context.Response.OnCompleted(iRunOnResponseCompleted, context);
#endregion
try
{
await next(context);
}
catch (Exception ex)
{
#region IRunOnError
var errorCmds = serviceProvider.GetServices<IRunOnError>();
foreach (var cmd in befores)
{
cmd.Execute();
}
#endregion
throw;
}
#region IRunAfterEachRequest
var afters = serviceProvider.GetServices<IRunAfterEachRequest>();
foreach (var cmd in afters)
{
cmd.Execute();
}
#endregion
}
示例2: BuildTenantPipeline
// Build the middleware pipeline for the current tenant
public RequestDelegate BuildTenantPipeline(ShellSettings shellSettings, IServiceProvider serviceProvider)
{
var startups = serviceProvider.GetServices<IStartup>();
var inlineConstraintResolver = serviceProvider.GetService<IInlineConstraintResolver>();
IApplicationBuilder appBuilder = new ApplicationBuilder(serviceProvider);
string routePrefix = "";
if (!string.IsNullOrWhiteSpace(shellSettings.RequestUrlPrefix))
{
routePrefix = shellSettings.RequestUrlPrefix + "/";
}
var routeBuilder = new RouteBuilder(appBuilder)
{
DefaultHandler = serviceProvider.GetRequiredService<MvcRouteHandler>()
};
var prefixedRouteBuilder = new PrefixedRouteBuilder(routePrefix, routeBuilder, inlineConstraintResolver);
// Register one top level TenantRoute per tenant. Each instance contains all the routes
// for this tenant.
// In the case of several tenants, they will all be checked by ShellSettings. To optimize
// the TenantRoute resolution we can create a single Router type that would index the
// TenantRoute object by their ShellSetting. This way there would just be one lookup.
// And the ShellSettings test in TenantRoute would also be useless.
foreach (var startup in startups)
{
startup.Configure(appBuilder, prefixedRouteBuilder, serviceProvider);
}
// The default route is added to each tenant as a template route, with a prefix
prefixedRouteBuilder.Routes.Add(new Route(
prefixedRouteBuilder.DefaultHandler,
"Default",
"{area:exists}/{controller}/{action}/{id?}",
null,
null,
null,
inlineConstraintResolver)
);
// Add home page route
routeBuilder.Routes.Add(new HomePageRoute(shellSettings.RequestUrlPrefix, routeBuilder, inlineConstraintResolver));
var router = prefixedRouteBuilder.Build();
appBuilder.UseRouter(router);
var pipeline = appBuilder.Build();
return pipeline;
}
示例3: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider provider)
{
loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc();
// activate interactors
foreach(var interactor in provider.GetServices<IInteractor>())
{
interactor.Activate();
}
}
示例4: StartUp
private static void StartUp(IServiceProvider serviceProvider)
{
var starts = serviceProvider.GetServices<IRunAtStartup>();
foreach (var cmd in starts)
{
cmd.Execute();
}
}
示例5: Init
private static void Init(IServiceProvider serviceProvider)
{
var inits = serviceProvider.GetServices<IRunAtInit>();
foreach (var cmd in inits)
{
cmd.Execute();
}
}
示例6: ServiceResolver
public ServiceResolver(IServiceProvider provider)
{
_Services = provider.GetServices();
}