/// <summary> /// Initializes a new instance of the <see cref="LifetimeScope"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="rule"></param> public LifetimeScope(IRegisterRuleContainer container, IRegisterRule rule) { this.container = container; this.cachedKey = rule == null ? typeof(LifetimeScope).Name : rule.ToString(); this.context = new ResolveContext() { Disposer = null, Singleton = new SingletonComponentLifeStyleStorager() { ContextCache = new TransientContextCache() }, Scope = null }; }
/// <summary> /// Initializes a new instance of the <see cref="LifetimeScope"/> class. /// </summary> /// <param name="parent">The parent.</param> private LifetimeScope(LifetimeScope parent) { this.container = parent.container; this.parent = parent; this.cachedKey = parent.cachedKey; this.context = new ResolveContext() { Disposer = new Disposer(), Scope = new ScopeComponentLifeStyleStorager() { ContextCache = new TransientContextCache() }, Singleton = parent.context.Singleton, }; //自己resolve自己的时候,直接返回自身 this.context.Scope.ContextCache.Set <ILifetimeScope>(cachedKey, this); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceRegister"/> class. /// </summary> /// <param name="register"></param> /// <param name="option"></param> public ServiceRegister(IRegisterRuleContainer register, IValuableOption <UnableRegisterRule> option) { this.register = register; this.option = option; }