• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ILifetimeScope类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ILifetimeScope的典型用法代码示例。如果您正苦于以下问题:C# ILifetimeScope类的具体用法?C# ILifetimeScope怎么用?C# ILifetimeScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ILifetimeScope类属于命名空间,在下文中一共展示了ILifetimeScope类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetChildLifetimeScope

        /// <summary>
        /// Creates a new child scope or returns an existing child scope.
        /// </summary>
        /// <param name="parentScope">The current parent container.</param>
        /// <param name="scopeKindTag">
        /// A tag to identify this kind of scope so it can be reused to share objects 
        /// through fancy registration extensions (e.g. InstancePerSPSite, InstancePerSPWeb)
        /// </param>
        /// <param name="childScopeKey">A key to uniquely identify this scope within the container.</param>
        /// <returns>The child scope for the uniquely identified resource</returns>
        public ILifetimeScope GetChildLifetimeScope(ILifetimeScope parentScope, string scopeKindTag, string childScopeKey)
        {
            ILifetimeScope ensuredScope = null;

            // Don't bother locking if the instance is already created
            if (this.childScopes.ContainsKey(childScopeKey))
            {
                // Return the already-initialized container right away
                ensuredScope = this.childScopes[childScopeKey];
            }
            else
            {
                // Only one scope should be registered at a time in this helper instance, to be on the safe side
                lock (this.childScopesLockObject)
                {
                    // Just in case, check again (because the assignment could have happened before we took hold of lock)
                    if (this.childScopes.ContainsKey(childScopeKey))
                    {
                        ensuredScope = this.childScopes[childScopeKey];
                    }
                    else
                    {
                        // This scope will never be disposed, i.e. it will live as long as the parent
                        // container, provided no one calls Dispose on it.
                        // The newly created scope is meant to sandbox InstancePerLifetimeScope-registered objects
                        // so that they get shared only within a boundary uniquely identified by the key.
                        ensuredScope = parentScope.BeginLifetimeScope(scopeKindTag);
                        this.childScopes[childScopeKey] = ensuredScope;
                    }
                }
            }

            return ensuredScope;
        }
开发者ID:ASAGARG,项目名称:Dynamite,代码行数:44,代码来源:ChildScopeFactory.cs


示例2: WebApplicationComponent

 //-----------------------------------------------------------------------------------------------------------------------------------------------------
 public WebApplicationComponent(IWebAppEndpoint endpoint, Auto<ILogger> logger, IComponentContext componentContext)
 {
     _app = endpoint.Contract;
     _address = endpoint.Address;
     _logger = logger.Instance;
     _container = (ILifetimeScope)componentContext;
 }
开发者ID:votrongdao,项目名称:NWheels,代码行数:8,代码来源:WebApplicationComponent.cs


示例3: AutofacDependencyResolver

        /// <summary>
        /// Initializes a new instance of the <see cref="AutofacDependencyResolver" /> class.
        /// </summary>
        /// <param name="lifetimeScope">The lifetime scope that services will be resolved from.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown if <paramref name="lifetimeScope" /> is <see langword="null" />.
        /// </exception>
        public AutofacDependencyResolver(ILifetimeScope lifetimeScope) {
            if (lifetimeScope == null)
                throw new ArgumentNullException("lifetimeScope");

            _lifetimeScope = lifetimeScope;
            _lifetimeScope.ComponentRegistry.AddRegistrationSource(this);
        }
开发者ID:micrak,项目名称:anurgath-shoutbox,代码行数:14,代码来源:AutofacDependencyResolver.cs


示例4: ApplicationStartup

        protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
        {
            pipelines.OnError.AddItemToEndOfPipeline((context, exception) =>
                                                         {
                                                             var message = string.Format("Exception: {0}", exception);
                                                             new ElmahErrorHandler.LogEvent(message).Raise();
                                                             return null;
                                                         });

            pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx =>
                                                               {
                                                                   var lang = ctx.Request.Headers.AcceptLanguage.FirstOrDefault();
                                                                   if (lang != null)
                                                                   {
                                                                       // Accepted language can be something like "fi-FI", but it can also can be like fi-FI,fi;q=0.9,en;q=0.8
                                                                       if (lang.Contains(","))
                                                                           lang = lang.Substring(0, lang.IndexOf(","));

                                                                       System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
                                                                       System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                                                                   }
                                                                   return null;
                                                               });

            DoMigrations();
        }
开发者ID:meatherly,项目名称:Ideastrike,代码行数:26,代码来源:IdeastrikeBootstrapper.cs


示例5: ApplicationStartup

        protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            // register interfaces/implementations
            container.Update(builder => builder
                //.RegisterType<CouchDbTShirtRepository>()
                .RegisterType<MockedTShirtRepository>()
                .As<ITShirtRepository>());

            // register MyCouchStore parameter for couchdb repo classes
            container.Update(builder => builder
                .RegisterType<MyCouchStore>()
                .As<IMyCouchStore>()
                .UsingConstructor(typeof (string), typeof (string))
                .WithParameters(new [] {
                    new NamedParameter("dbUri","http://seraya_dba:[email protected]:5984/"),
                    new NamedParameter("dbName","cshirts")
                })
            );

            // TODO: remove after implementing REST-Api & replacing razor with angular
            // display razor error messages
            StaticConfiguration.DisableErrorTraces = false;
        }
开发者ID:takahser,项目名称:C-Shirts,代码行数:25,代码来源:Bootstrapper.cs


示例6: AutofacLifetimeScopeProvider

        /// <summary>
        /// 初始化一个 <see cref="AutofacLifetimeScopeProvider"/> 类的实例.
        /// </summary>
        /// <param name="container">
        /// 容器.
        /// </param>
        public AutofacLifetimeScopeProvider(ILifetimeScope container)
        {
            Guard.ArgumentNotNull(() => container);

            this.container = container;
            AutofacRequestLifetimeHttpModule.SetLifetimeScopeProvider(this);
        }
开发者ID:ZhaoRd,项目名称:Ren_Framework,代码行数:13,代码来源:AutofacLifetimeScopeProvider.cs


示例7: Rebuild

 public Rebuild(IStoreEvents eventStore, IDomainUpdateServiceBusHandlerHook hook, ILifetimeScope container, IMongoContext mongo)
 {
     _eventStore = eventStore;
     _hook = hook;
     _container = container;
     _mongo = mongo;
 }
开发者ID:kcornelis,项目名称:FreelanceManager.NET,代码行数:7,代码来源:Rebuild.cs


示例8: AutofacJobFactory

 /// <summary>
 ///     Initializes a new instance of the <see cref="AutofacJobFactory" /> class.
 /// </summary>
 /// <param name="lifetimeScope">The lifetime scope.</param>
 /// <param name="scopeName">Name of the scope.</param>
 public AutofacJobFactory(ILifetimeScope lifetimeScope, string scopeName)
 {
     if (lifetimeScope == null) throw new ArgumentNullException("lifetimeScope");
     if (scopeName == null) throw new ArgumentNullException("scopeName");
     _lifetimeScope = lifetimeScope;
     _scopeName = scopeName;
 }
开发者ID:Boichu87,项目名称:Autofac.Extras.Quartz,代码行数:12,代码来源:AutofacJobFactory.cs


示例9: AutofacDependencyResolver

        /// <summary>
        /// Initializes a new instance of the <see cref="AutofacDependencyResolver" /> class.
        /// </summary>
        /// <param name="lifetimeScope">The lifetime scope that services will be resolved from.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown if <paramref name="lifetimeScope" /> is <see langword="null" />.
        /// </exception>
        public AutofacDependencyResolver(ILifetimeScope lifetimeScope)
        {
            if (lifetimeScope == null)
                throw new ArgumentNullException("lifetimeScope");

            _lifetimeScope = lifetimeScope;
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:14,代码来源:AutofacDependencyResolver.cs


示例10: RequestStartup

        protected override void RequestStartup(ILifetimeScope container, IPipelines pipelines, NancyContext context)
        {
            // No registrations should be performed in here, however you may
            // resolve things that are needed during request startup.

            FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration()
            {
                RedirectUrl = "~/account/login",
                UserMapper = container.Resolve<IUserMapper>(),
            });

            pipelines.BeforeRequest.AddItemToEndOfPipeline(c =>
            {
                if (c.CurrentUser.IsAuthenticated())
                {
                    container.Resolve<ITenantContext>().SetTenantId(c.CurrentUser.AsAuthenticatedUser().Id, c.CurrentUser.HasClaim("Admin"));
                    c.ViewBag.UserName = c.CurrentUser.AsAuthenticatedUser().FullName;
                    c.ViewBag.IsAdmin = c.CurrentUser.HasClaim("Admin");
                }
                else
                    container.Resolve<ITenantContext>().SetTenantId(null, false);

                return null;
            });
        }
开发者ID:kcornelis,项目名称:FreelanceManager.NET,代码行数:25,代码来源:NancyTestBootstrapper.cs


示例11: ConfigureApplicationContainer

        protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
        {
            var setup = new Setup((IContainer)existingContainer);

            // defaults
            setup.WithGuidGenerator();
            setup.WithThreadStaticTenantContext();
            setup.WithMongo("MongoConnectionReadModel");
            setup.RegisterReadModelRepositories();

            // web specific
            var builder = new ContainerBuilder();
            builder.RegisterType<NancyUserMapper>().As<IUserMapper>();
            builder.RegisterType<StaticContentResolverForInMemory>().As<IStaticContentResolver>();
            builder.RegisterType<ExcelService>().As<IExcelService>();
            builder.Update(setup.Container.ComponentRegistry);

            // bus
            setup.WithInMemoryBus();
            setup.RegisterReadModelHandlers();

            // eventstore
            setup.WithMongoEventStore("MongoConnectionEventStore",
                new AuthorizationPipelineHook(setup.Container),
                new MessageDispatcher(setup.Container),
                false);

            // start the bus
            setup.Container.Resolve<IServiceBus>().Start(ConfigurationManager.AppSettings["serviceBusEndpoint"]);
        }
开发者ID:kcornelis,项目名称:FreelanceManager.NET,代码行数:30,代码来源:NancyTestBootstrapper.cs


示例12: PluginHttpApi

 public PluginHttpApi(
     ILogger logger,
     ILifetimeScope lifetimeScope)
 {
     _logger = logger;
     _lifetimeScope = lifetimeScope;
 }
开发者ID:rasmus,项目名称:TheBorg,代码行数:7,代码来源:PluginHttpApi.cs


示例13: ApplicationStartup

        protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
        {
            pipelines.OnError.AddItemToEndOfPipeline(LogException);
            pipelines.BeforeRequest.AddItemToEndOfPipeline(DetectLanguage);

            DoMigrations();
        }
开发者ID:shiftkey,项目名称:Ideastrike,代码行数:7,代码来源:IdeastrikeBootstrapper.cs


示例14: ConfigureApplicationContainer

        protected override void ConfigureApplicationContainer(ILifetimeScope container)
        {
            base.ConfigureApplicationContainer(container);

            var builder = new ContainerBuilder();

            builder.RegisterType<AppSettings>().As<IAppSettings>().SingleInstance();
            builder.RegisterType<DummyMailChimpWebhooks>().As<IMailChimpWebhooks>().SingleInstance();
            builder.RegisterType<DummyMailgunWebhooks>().As<IMailgunWebhooks>().SingleInstance();
            builder.RegisterType<AzureTableStorageTodoService>().As<ITodoService>().SingleInstance();

            // Consumers and sagas
            builder.RegisterAssemblyTypes(typeof(Bootstrapper).Assembly)
                .Where(t => t.Implements<ISaga>() ||
                            t.Implements<IConsumer>())
                .AsSelf();

            // Saga repositories
            builder.RegisterGeneric(typeof(InMemorySagaRepository<>))
                .As(typeof(ISagaRepository<>))
                .SingleInstance();

            // Service bus
            builder.Register(c => ServiceBusFactory.New(sbc =>
            {
                sbc.ReceiveFrom("loopback://localhost/queue");
                sbc.Subscribe(x => x.LoadFrom(container));
            })).As<IServiceBus>().SingleInstance();

            builder.Update(container.ComponentRegistry);
        }
开发者ID:rapidexpert,项目名称:SlackCommander,代码行数:31,代码来源:Bootstrapper.cs


示例15: Configure

        public static HttpConfiguration Configure(IdentityServerOptions options, ILifetimeScope container)
        {
            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();
            config.SuppressDefaultHostAuthentication();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            config.Services.Add(typeof(IExceptionLogger), new LogProviderExceptionLogger());
            config.Services.Replace(typeof(IHttpControllerTypeResolver), new HttpControllerTypeResolver());
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;

            if (options.LoggingOptions.EnableWebApiDiagnostics)
            {
                var liblog = new TraceSource("LibLog");
                liblog.Switch.Level = SourceLevels.All;
                liblog.Listeners.Add(new LibLogTraceListener());

                var diag = config.EnableSystemDiagnosticsTracing();
                diag.IsVerbose = options.LoggingOptions.WebApiDiagnosticsIsVerbose;
                diag.TraceSource = liblog;
            }

            ConfigureRoutes(options, config);

            return config;
        }
开发者ID:0mn1bu5,项目名称:IdentityServer3,代码行数:30,代码来源:WebApiConfig.cs


示例16: DatabaseLock

 public DatabaseLock(
     ILifetimeScope lifetimeScope,
     IClock clock)
 {
     _lifetimeScope = lifetimeScope;
     _clock = clock;
 }
开发者ID:hqmirror,项目名称:Piedone.HelpfulLibraries,代码行数:7,代码来源:DatabaseLock.cs


示例17: ConfigureApplicationContainer

 protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
 {
     var builder = new ContainerBuilder();
     _tasks.ForEach(task => task.Task.Invoke(builder));
     builder.Update(existingContainer.ComponentRegistry);
     base.ConfigureApplicationContainer(existingContainer);
 }
开发者ID:rsiwady29,项目名称:FireTower,代码行数:7,代码来源:Bootstrapper.cs


示例18: AutofacMediatorBuilder

 public AutofacMediatorBuilder(ILifetimeScope container)
 {
     _key = HandlerKey;
     _asyncKey = AsyncHandlerKey;
     _container = container;
     _builder = new ContainerBuilder();
 }
开发者ID:jfenschQSI,项目名称:MediatR.Extensions,代码行数:7,代码来源:AutofacMediatorBuilder.cs


示例19: ConfigureRequestContainer

 // The bootstrapper enables you to reconfigure the composition of the framework,
 // by overriding the various methods and properties.
 // For more information https://github.com/NancyFx/Nancy/wiki/Bootstrapper
 //protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
 //{
 //    // No registrations should be performed in here, however you may
 //    // resolve things that are needed during application startup.
 //}
 //protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
 //{
 //    // Perform registration that should have an application lifetime
 //}
 protected override void ConfigureRequestContainer(ILifetimeScope container, NancyContext context)
 {
     // Perform registrations that should have a request lifetime
     var builder = new ContainerBuilder();
     builder.RegisterModule(new ServicesModule());
     builder.Update(container.ComponentRegistry);
 }
开发者ID:kjellski,项目名称:MongoRestLog,代码行数:19,代码来源:Bootstrapper.cs


示例20: Resolve

        protected override void Resolve(ILifetimeScope container) {
            _compositionStrategy = container.Resolve<CompositionStrategy>();
            _compositionStrategy.Logger = container.Resolve<ILogger>();

            var alphaExtension = new ExtensionDescriptor {
                Id = "Alpha",
                Name = "Alpha",
                ExtensionType = "Module"
            };

            var alphaFeatureDescriptor = new FeatureDescriptor {
                Id = "Alpha",
                Name = "Alpha",
                Extension = alphaExtension
            };

            var betaFeatureDescriptor = new FeatureDescriptor {
                Id = "Beta",
                Name = "Beta",
                Extension = alphaExtension,
                Dependencies = new List<string> {
                    "Alpha"
                }
            };

            alphaExtension.Features = new List<FeatureDescriptor> {
                alphaFeatureDescriptor,
                betaFeatureDescriptor
            };

            _availableExtensions = new[] {
                alphaExtension
            };

            _installedFeatures = new List<Feature> {
                new Feature {
                    Descriptor = alphaFeatureDescriptor,
                    ExportedTypes = new List<Type> {
                        typeof(AlphaDependency)
                    }
                },
                new Feature {
                    Descriptor = betaFeatureDescriptor,
                    ExportedTypes = new List<Type> {
                        typeof(BetaDependency)
                    }
                }
            };

            _loggerMock.Setup(x => x.IsEnabled(It.IsAny<LogLevel>())).Returns(true);

            _extensionManager.Setup(x => x.AvailableExtensions()).Returns(() => _availableExtensions);

            _extensionManager.Setup(x => x.AvailableFeatures()).Returns(() =>
                _extensionManager.Object.AvailableExtensions()
                .SelectMany(ext => ext.Features)
                .ToReadOnlyCollection());

            _extensionManager.Setup(x => x.LoadFeatures(It.IsAny<IEnumerable<FeatureDescriptor>>())).Returns(() => _installedFeatures);
        }
开发者ID:Higea,项目名称:Orchard,代码行数:60,代码来源:CompositionStrategyTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ILine类代码示例发布时间:2022-05-24
下一篇:
C# ILifecycleManager类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap