コード例 #1
0
            public ScopedFactory(IResolverContext context)
            {
                _scope = context.OpenScope();

                //use this factory within it`s scope
                _scope.Use <IScopedFactory>(this);
            }
コード例 #2
0
ファイル: InitializerTests.cs プロジェクト: nodyang/DryIoc
        static IResolverContext ScopeSession(IResolverContext container, string id)
        {
            var scope   = container.OpenScope();
            var session = scope.Resolve <Session>();

            return(scope);
        }
            public IFoo GetOrCreate2(IResolverContext ctx, FactoryDelegate <Func <string, IFoo> > fooFactory, string address)
            {
                // fancy ensuring that we have a single new Scope created and stored
                var scopeEntry = _scopes.GetEntryOrDefault(address);

                if (scopeEntry == null)
                {
                    Ref.Swap(ref _scopes, address, (x, a) => x.AddOrKeep(a));
                    scopeEntry = _scopes.GetEntryOrDefault(address);
                }

                lock (scopeEntry)
                    if (scopeEntry.Value == null || scopeEntry.Value.IsDisposed)
                    {
                        scopeEntry.Value = ctx.OpenScope(address);
                    }

                return(fooFactory(scopeEntry.Value).Invoke(address));
            }
コード例 #4
0
        private static View ConstructView(IResolverContext context, Type viewType)
        {
            var scope = context.OpenScope();
            var svl   = scope.Resolve <IScopedViewLocator>();
            var view  = scope.Resolve(viewType) as View;

            svl.View = view;
            CometUtilities.SetMappings(view);

            var configurations = scope.ResolveMany <IViewConfiguration>();

            foreach (var config in configurations)
            {
                config.Configure(view);
            }

            var stateFieldNames = CometUtilities.CheckForStateAttributes(viewType).Select(x => x.Name).ToArray();

            scope.InjectPropertiesAndFields(view, stateFieldNames);
            return(view);
        }
コード例 #5
0
 public Session(IResolverContext cont)
 {
     _scope = cont.OpenScope("test");
     var dep = _scope.New <Dependency>();
 }
コード例 #6
0
 /// <summary>
 /// Creates a child scope
 /// </summary>
 /// <returns></returns>
 public ILocatorScoped CreateScope() => new DryIocLocatorScoped(_resolveContext.OpenScope(), this);