Beispiel #1
0
        public virtual void SwitchInRootResolver(RootDependencyResolver value)
        {
            ResolverChain secondResolver = new ResolverChain();

            secondResolver.Add((IDbDependencyResolver)value);
            this._resolvers.Second.Resolvers.Skip <IDbDependencyResolver>(1).Each <IDbDependencyResolver>(new Action <IDbDependencyResolver>(secondResolver.Add));
            this._rootResolver = value;
            this._resolvers    = new CompositeResolver <ResolverChain, ResolverChain>(this._resolvers.First, secondResolver);
        }
Beispiel #2
0
 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));
 }
Beispiel #3
0
 public InternalConfiguration(
     ResolverChain appConfigChain                  = null,
     ResolverChain normalResolverChain             = null,
     RootDependencyResolver rootResolver           = null,
     AppConfigDependencyResolver appConfigResolver = null,
     Func <DbDispatchers> dispatchers              = null)
 {
     this._rootResolver = rootResolver ?? new RootDependencyResolver();
     this._resolvers    = new CompositeResolver <ResolverChain, ResolverChain>(appConfigChain ?? new ResolverChain(), normalResolverChain ?? new ResolverChain());
     this._resolvers.Second.Add((IDbDependencyResolver)this._rootResolver);
     this._resolvers.First.Add((IDbDependencyResolver)(appConfigResolver ?? new AppConfigDependencyResolver(AppConfig.DefaultInstance, this, (ProviderServicesFactory)null)));
     this._dispatchers = dispatchers ?? (Func <DbDispatchers>)(() => DbInterception.Dispatch);
 }
Beispiel #4
0
        /// <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);
        }
            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));
                }
            }