Exemple #1
0
        public InternalConfiguration(ResolverChain appConfigChain, ResolverChain normalResolverChain, RootDependencyResolver rootResolver)
        {
            DebugCheck.NotNull(appConfigChain);
            DebugCheck.NotNull(normalResolverChain);

            _rootResolver = rootResolver;
            _resolvers    = new CompositeResolver <ResolverChain, ResolverChain>(appConfigChain, normalResolverChain);
            _resolvers.Second.Add(_rootResolver);
        }
 public InternalConfiguration(
     ResolverChain appConfigChain                  = null,
     ResolverChain normalResolverChain             = null,
     RootDependencyResolver rootResolver           = null,
     AppConfigDependencyResolver appConfigResolver = null)
 {
     _rootResolver = rootResolver ?? new RootDependencyResolver();
     _resolvers    = new CompositeResolver <ResolverChain, ResolverChain>(appConfigChain ?? new ResolverChain(), normalResolverChain ?? new ResolverChain());
     _resolvers.Second.Add(_rootResolver);
     _resolvers.First.Add(appConfigResolver ?? new AppConfigDependencyResolver(AppConfig.DefaultInstance, this));
 }
        public void GetService_can_be_accessed_from_multiple_threads_concurrently()
        {
            for (var i = 0; i < 30; i++)
            {
                var bag      = new ConcurrentBag <IPilkington>();
                var karl1    = new Mock <IPilkington>().Object;
                var resolver = new CompositeResolver <IDbDependencyResolver, IDbDependencyResolver>(
                    new SingletonDependencyResolver <IPilkington>(karl1),
                    new SingletonDependencyResolver <IPilkington>(new Mock <IPilkington>().Object));

                ExecuteInParallel(() => bag.Add(resolver.GetService <IPilkington>()));

                Assert.Equal(20, bag.Count);
                Assert.True(bag.All(c => karl1 == c));
            }
        }
        /// <summary>
        ///     This method is not thread-safe and should only be used to switch in a different root resolver
        ///     before the configuration is locked and set. It is used for pushing a new configuration by
        ///     DbContextInfo while maintaining legacy settings (such as database initializers) that are
        ///     set on the root resolver.
        /// </summary>
        public virtual void SwitchInRootResolver(RootDependencyResolver value)
        {
            DebugCheck.NotNull(value);

            Debug.Assert(!_isLocked);

            // The following is not thread-safe but this code is only called when pushing a configuration
            // and happens to a new DbConfiguration before it has been set and locked.
            var newChain = new ResolverChain();

            newChain.Add(value);
            _resolvers.Second.Resolvers.Skip(1).Each(newChain.Add);

            _rootResolver = value;
            _resolvers    = new CompositeResolver <ResolverChain, ResolverChain>(_resolvers.First, newChain);
        }