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


C# ILifetimeScope类代码示例

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


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


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