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


C# IServiceProvider.GetServices方法代码示例

本文整理汇总了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
        }
开发者ID:dburriss,项目名称:AspNetLifecycle,代码行数:44,代码来源:LifecycleMiddleware.cs

示例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;
        }
开发者ID:vairam-svs,项目名称:Orchard2,代码行数:57,代码来源:OrchardRouterMiddleware.cs

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

示例4: StartUp

 private static void StartUp(IServiceProvider serviceProvider)
 {
     var starts = serviceProvider.GetServices<IRunAtStartup>();
     foreach (var cmd in starts)
     {
         cmd.Execute();
     }
 }
开发者ID:dburriss,项目名称:AspNetLifecycle,代码行数:8,代码来源:LifecycleExtensions.cs

示例5: Init

 private static void Init(IServiceProvider serviceProvider)
 {
     var inits = serviceProvider.GetServices<IRunAtInit>();
     foreach (var cmd in inits)
     {
         cmd.Execute();
     }
 }
开发者ID:dburriss,项目名称:AspNetLifecycle,代码行数:8,代码来源:LifecycleExtensions.cs

示例6: ServiceResolver

 public ServiceResolver(IServiceProvider provider)
 {
     _Services = provider.GetServices();
 }
开发者ID:jcbozonier,项目名称:irontwit,代码行数:4,代码来源:ServiceResolver.cs


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