public FactoryResolutionPipeline(Foundation foundation, IServiceLocatorAdapter adapter, IServiceLocatorStore store)
        {
            var pipeline = new PostResolutionPipeline(foundation, adapter, store);

            Add(new ConditionalPipelineItem(foundation, adapter, store, pipeline));
            Add(new DefaultPipelineItem(foundation, adapter, store, pipeline));
        }
Esempio n. 2
0
        protected ServiceLocator(IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store)
        {
            this.serviceLocator    = serviceLocator;
            this.store             = store;
            foundation             = new Foundation();
            pipeline               = new DefaultResolutionPipeline(foundation, serviceLocator, this.store);
            factoryPipeline        = new FactoryResolutionPipeline(foundation, serviceLocator, this.store);
            postResolutionPipeline = new PostResolutionPipeline(foundation, serviceLocator, store);

            registrationTemplate = new DefaultMetaRegistrationTemplate(serviceLocator);

            serviceLocator.Register(typeof(Transient), typeof(Transient));
            serviceLocator.Register(typeof(Singleton), typeof(Singleton));
            serviceLocator.RegisterInstance(typeof(IServiceLocatorAdapter), serviceLocator);
            serviceLocator.RegisterInstance(typeof(IServiceLocator), this);
            serviceLocator.RegisterInstance(typeof(Microsoft.Practices.ServiceLocation.IServiceLocator), this);
            serviceLocator.RegisterInstance(typeof(Foundation), this.foundation);
            serviceLocator.RegisterInstance(typeof(IServiceLocatorStore), this.store);
            serviceLocator.RegisterInstance(typeof(IContextStore), this.store.Get <IContextStore>());
            serviceLocator.RegisterInstance(typeof(IExecutionStore), this.store.Get <IExecutionStore>());
            serviceLocator.RegisterInstance(typeof(IResolutionStore), this.store.Get <IResolutionStore>());

            var binPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath
                          ?? AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            Register(Load.FromAssembliesIn(binPath, binPath + @"\Plugins\", ".plugin"));
        }
        public override void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            var mappedFromType = registration.GetMappedFromType();
            var mappedToType = registration.GetMappedToType();

            if (mappedFromType != mappedToType)
            {
                adapter.RegisterFactoryMethod(mappedFromType, () => pipeline.Execute(mappedFromType));
                RegisterLazy(adapter, mappedFromType, pipeline);
                adapter.Register(mappedToType, mappedToType);
                RegisterContextual(adapter, mappedToType);
            }
            else
            {
                var serviceLocator = adapter.GetInstance<IServiceLocator>();
                adapter.RegisterFactoryMethod(mappedToType, () =>
                {
                    var instance = serviceLocator.GetInstance(mappedToType, "default." + mappedToType, new IResolutionArgument[0]);
                    return instance;
                });
                serviceLocator.Register(new NamedRegistration(mappedToType, mappedToType, "default." + mappedToType));
            }

            RegisterLazy(adapter, mappedToType, pipeline);
            RegisterTypeResolver(adapter, mappedFromType);
            RegisterContextual(adapter, mappedFromType);
        }
Esempio n. 4
0
 public DefaultPipelineItem(Foundation foundation, IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store, PostResolutionPipeline pipeline) : base(foundation, serviceLocator, store)
 {
     this.pipeline = pipeline;
     this.store.Get <IExecutionStore>().WireEvent((ITypeRequester)this);
     this.store.Get <IExecutionStore>().WireEvent((ITypeResolver)this);
     this.registrationStore = foundation.StoreFor <DefaultRegistrationStore>();
 }
        public DefaultResolutionPipeline(Foundation foundation, IServiceLocatorAdapter adapter, IServiceLocatorStore store)
            : base(foundation, adapter, store)
        {
            var pipeline = new PostResolutionPipeline(foundation, adapter, store);

            Add(new AdapterPipelineItem(foundation, adapter, store, pipeline));
        }
        public FactoryResolutionPipeline(Foundation foundation, IServiceLocatorAdapter adapter, IServiceLocatorStore store)
        {
            var pipeline = new PostResolutionPipeline(foundation, adapter, store);

            Add(new ConditionalPipelineItem(foundation, adapter, store, pipeline));
            Add(new DefaultPipelineItem(foundation, adapter, store, pipeline));
        }
        public override void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            var mappedFromType = registration.GetMappedFromType();
            var mappedToType   = registration.GetMappedToType();

            if (mappedFromType != mappedToType)
            {
                adapter.RegisterFactoryMethod(mappedFromType, () => pipeline.Execute(mappedFromType));
                RegisterLazy(adapter, mappedFromType, pipeline);
                adapter.Register(mappedToType, mappedToType);
                RegisterContextual(adapter, mappedToType);
            }
            else
            {
                var serviceLocator = adapter.GetInstance <IServiceLocator>();
                adapter.RegisterFactoryMethod(mappedToType, () =>
                {
                    var instance = serviceLocator.GetInstance(mappedToType, "default." + mappedToType, new IResolutionArgument[0]);
                    return(instance);
                });
                serviceLocator.Register(new NamedRegistration(mappedToType, mappedToType, "default." + mappedToType));
            }

            RegisterLazy(adapter, mappedToType, pipeline);
            RegisterTypeResolver(adapter, mappedFromType);
            RegisterContextual(adapter, mappedFromType);
        }
        public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            if (registration is ConstructorRegistration)
            {
                var constructorRegistration = registration as ConstructorRegistration;

                store.Get <IInjectionOverrideStore>().Add(constructorRegistration.Arguments);
            }
        }
        public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            if (registration is ConstructorRegistration)
            {
                var constructorRegistration = registration as ConstructorRegistration;

                store.Get<IInjectionOverrideStore>().Add(constructorRegistration.Arguments);
            }
        }
Esempio n. 10
0
        public override void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            var namedRegistration = (INamedRegistration)registration;

            var mappedTo = registration.GetMappedTo();

            adapter.RegisterInstanceWithName(registration.GetMappedToType(), mappedTo, namedRegistration.Key);
            adapter.RegisterInstanceWithName(registration.GetMappedFromType(), mappedTo, namedRegistration.Key);
        }
        public override void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            var namedRegistration = (INamedRegistration)registration;

            var mappedTo = registration.GetMappedTo();

            adapter.RegisterInstanceWithName(registration.GetMappedToType(), mappedTo, namedRegistration.Key);
            adapter.RegisterInstanceWithName(registration.GetMappedFromType(), mappedTo, namedRegistration.Key);
        }
Esempio n. 12
0
        protected void RegisterLazy(IServiceLocatorAdapter adapter, Type type, ResolutionPipeline pipeline)
        {
            Type lazyLoader = typeof(Func <>).MakeGenericType(type);

            Expression <Func <object> > func = () => pipeline.Execute(type);

            var lambda = Expression.Lambda(lazyLoader, Expression.Convert(Expression.Invoke(func), type)).Compile();

            adapter.RegisterFactoryMethod(lazyLoader, () => lambda);
        }
        protected void RegisterLazy(IServiceLocatorAdapter adapter, Type type, ResolutionPipeline pipeline)
        {
            Type lazyLoader = typeof (Func<>).MakeGenericType(type);

            Expression<Func<object>> func = () => pipeline.Execute(type);

            var lambda = Expression.Lambda(lazyLoader, Expression.Convert(Expression.Invoke(func), type)).Compile();

            adapter.RegisterFactoryMethod(lazyLoader, () => lambda);
        }
Esempio n. 14
0
        protected void RegisterNamedLazy(IServiceLocatorAdapter adapter, Type type, string key)
        {
            var serviceLocator = (IServiceLocator)adapter.GetInstance(typeof (IServiceLocator));
            Type lazyLoader = typeof(Func<,>).MakeGenericType(typeof(string), type);

            Expression<Func<string, object>> func = x => serviceLocator.GetInstance(type, x);
            var parameter = Expression.Parameter(typeof (string), "param1");
            var lambda = Expression.Lambda(lazyLoader, Expression.Convert(Expression.Invoke(func, parameter), type), parameter).Compile();

            adapter.RegisterFactoryMethod(lazyLoader, () => lambda);
        }
Esempio n. 15
0
        protected void RegisterContextual(IServiceLocatorAdapter adapter, Type type)
        {
            var  serviceLocator = (IServiceLocator)adapter.GetInstance(typeof(IServiceLocator));
            Type lazyLoader     = typeof(Func <,>).MakeGenericType(typeof(object), type);

            Expression <Func <object, object> > func = x => serviceLocator.GetInstance(type, new ContextArgument(x));
            var parameter = Expression.Parameter(typeof(object), "param1");
            var lambda    = Expression.Lambda(lazyLoader, Expression.Convert(Expression.Invoke(func, parameter), type), parameter).Compile();

            adapter.RegisterFactoryMethod(lazyLoader, () => lambda);
        }
Esempio n. 16
0
        protected void RegisterNamedLazy(IServiceLocatorAdapter adapter, Type type, string key)
        {
            var  serviceLocator = (IServiceLocator)adapter.GetInstance(typeof(IServiceLocator));
            Type lazyLoader     = typeof(Func <,>).MakeGenericType(typeof(string), type);

            Expression <Func <string, object> > func = x => serviceLocator.GetInstance(type, x);
            var parameter = Expression.Parameter(typeof(string), "param1");
            var lambda    = Expression.Lambda(lazyLoader, Expression.Convert(Expression.Invoke(func, parameter), type), parameter).Compile();

            adapter.RegisterFactoryMethod(lazyLoader, () => lambda);
        }
        protected void RegisterContextual(IServiceLocatorAdapter adapter, Type type)
        {
            var serviceLocator = (IServiceLocator)adapter.GetInstance(typeof(IServiceLocator));
            Type lazyLoader = typeof(Func<,>).MakeGenericType(typeof(object), type);

            Expression<Func<object, object>> func = x => serviceLocator.GetInstance(type, new ContextArgument(x));
            var parameter = Expression.Parameter(typeof(object), "param1");
            var lambda = Expression.Lambda(lazyLoader, Expression.Convert(Expression.Invoke(func, parameter), type), parameter).Compile();

            adapter.RegisterFactoryMethod(lazyLoader, () => lambda);
        }
        public override void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            var mappedFromType = registration.GetMappedFromType();
            var mappedToType   = registration.GetMappedToType();

            adapter.RegisterFactoryMethod(mappedFromType, () => pipeline.Execute(mappedFromType));
            adapter.RegisterInstance(mappedToType, registration.GetMappedTo());
            RegisterLazy(adapter, mappedFromType, pipeline);
            RegisterLazy(adapter, mappedToType, pipeline);

            RegisterContextual(adapter, mappedFromType);
            RegisterContextual(adapter, mappedToType);
        }
        protected void RegisterTypeResolver(IServiceLocatorAdapter adapter, Type type)
        {
            Type lazyLoader = typeof(Func<,>).MakeGenericType(typeof(Type), type);
            if (adapter.HasTypeRegistered(lazyLoader)) return;

            var serviceLocator = (IServiceLocator)adapter.GetInstance(typeof(IServiceLocator));

            Expression<Func<object, object>> func = x => serviceLocator.GetInstance((Type)x);
            var parameter = Expression.Parameter(typeof(object), "param1");
            var lambda = Expression.Lambda(lazyLoader, Expression.Convert(Expression.Invoke(func, parameter), type), parameter).Compile();

            adapter.RegisterFactoryMethod(lazyLoader, () => lambda);
        }
        public override void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            var mappedFromType = registration.GetMappedFromType();
            var mappedToType = registration.GetMappedToType();

            adapter.RegisterFactoryMethod(mappedFromType, () => pipeline.Execute(mappedFromType));
            adapter.RegisterInstance(mappedToType, registration.GetMappedTo());
            RegisterLazy(adapter, mappedFromType, pipeline);
            RegisterLazy(adapter, mappedToType, pipeline);

            RegisterContextual(adapter, mappedFromType);
            RegisterContextual(adapter, mappedToType);
        }
Esempio n. 21
0
        public override void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            var namedRegistration = (INamedRegistration)registration;

            var mappedToType   = registration.GetMappedToType();
            var mappedFromType = registration.GetMappedFromType();

            adapter.RegisterWithName(mappedToType, mappedToType, namedRegistration.Key);
            adapter.RegisterWithName(mappedFromType, mappedToType, namedRegistration.Key);

            RegisterNamedLazy(adapter, mappedFromType, namedRegistration.Key);
            RegisterNamedLazy(adapter, mappedToType, namedRegistration.Key);
        }
Esempio n. 22
0
        public override void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
        {
            var namedRegistration = (INamedRegistration) registration;

            var mappedToType = registration.GetMappedToType();
            var mappedFromType = registration.GetMappedFromType();

            adapter.RegisterWithName(mappedToType, mappedToType, namedRegistration.Key);
            adapter.RegisterWithName(mappedFromType, mappedToType, namedRegistration.Key);

            RegisterNamedLazy(adapter, mappedFromType, namedRegistration.Key);
            RegisterNamedLazy(adapter, mappedToType, namedRegistration.Key);
        }
Esempio n. 23
0
        protected void RegisterTypeResolver(IServiceLocatorAdapter adapter, Type type)
        {
            Type lazyLoader = typeof(Func <,>).MakeGenericType(typeof(Type), type);

            if (adapter.HasTypeRegistered(lazyLoader))
            {
                return;
            }

            var serviceLocator = (IServiceLocator)adapter.GetInstance(typeof(IServiceLocator));

            Expression <Func <object, object> > func = x => serviceLocator.GetInstance((Type)x);
            var parameter = Expression.Parameter(typeof(object), "param1");
            var lambda    = Expression.Lambda(lazyLoader, Expression.Convert(Expression.Invoke(func, parameter), type), parameter).Compile();

            adapter.RegisterFactoryMethod(lazyLoader, () => lambda);
        }
Esempio n. 24
0
        protected ServiceLocator(IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store)
        {
            this.serviceLocator    = serviceLocator;
            this.store             = store;
            foundation             = new Foundation();
            pipeline               = new DefaultResolutionPipeline(foundation, serviceLocator, this.store);
            factoryPipeline        = new FactoryResolutionPipeline(foundation, serviceLocator, this.store);
            postResolutionPipeline = new PostResolutionPipeline(foundation, serviceLocator, store);

            registrationTemplate = new DefaultMetaRegistrationTemplate(serviceLocator);

            serviceLocator.Register(typeof(Transient), typeof(Transient));
            serviceLocator.Register(typeof(Singleton), typeof(Singleton));
            serviceLocator.RegisterInstance(typeof(IServiceLocatorAdapter), serviceLocator);
            serviceLocator.RegisterInstance(typeof(IServiceLocator), this);
            serviceLocator.RegisterInstance(typeof(Microsoft.Practices.ServiceLocation.IServiceLocator), this);
            serviceLocator.RegisterInstance(typeof(Foundation), this.foundation);
            serviceLocator.RegisterInstance(typeof(IServiceLocatorStore), this.store);
            serviceLocator.RegisterInstance(typeof(IContextStore), this.store.Get <IContextStore>());
            serviceLocator.RegisterInstance(typeof(IExecutionStore), this.store.Get <IExecutionStore>());
            serviceLocator.RegisterInstance(typeof(IResolutionStore), this.store.Get <IResolutionStore>());
        }
Esempio n. 25
0
 protected BasePipelineItem(Foundation foundation, IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store)
 {
     this.foundation = foundation;
     this.serviceLocator = serviceLocator;
     this.store = store;
 }
 public DefaultMetaRegistrationTemplate(IServiceLocatorAdapter locator)
 {
     this.locator = locator;
 }
Esempio n. 27
0
 public ConditionalPostResolutionPipelineItem(Foundation foundation, IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store) : base(foundation, serviceLocator, store)
 {
     registrationStore = foundation.StoreFor <ConditionalPostResolutionStore>();
 }
Esempio n. 28
0
 public WcfServiceLocator(IServiceLocatorAdapter serviceLocator)
     : base(serviceLocator, new WcfServiceLocatorStore())
 {
 }
 public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
 {
     store.Get<IAwarenessStore>().Add(registration.GetMappedTo());
 }
Esempio n. 30
0
 public HttpServiceLocator(IServiceLocatorAdapter serviceLocator, IContextStore store)
     : this(serviceLocator, new HttpServiceLocatorStore(store))
 {
 }
Esempio n. 31
0
 public ThreadedServiceLocator(IServiceLocatorAdapter serviceLocator)
     : base(serviceLocator, new ThreadedServiceLocatorStore())
 {
 }
 public DefaultMetaRegistrationTemplate(IServiceLocatorAdapter locator)
 {
     this.locator = locator;
 }
 public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
 {
     store.Get <IAwarenessStore>().Add(registration.GetMappedTo());
 }
Esempio n. 34
0
 protected HttpServiceLocator(IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store)
     : base(serviceLocator, store)
 {
 }
Esempio n. 35
0
 public ThreadedServiceLocator(IServiceLocatorAdapter serviceLocator)
     : base(serviceLocator, new ThreadedServiceLocatorStore())
 {
 }
Esempio n. 36
0
 public PostResolutionPipeline(Foundation foundation, IServiceLocatorAdapter adapter, IServiceLocatorStore store)
 {
     Add(new ConditionalPostResolutionPipelineItem(foundation, adapter, store));
     Add(new DefaultPostResolutionPipelineItem(foundation, adapter, store));
 }
Esempio n. 37
0
        public DefaultResolutionPipeline(Foundation foundation, IServiceLocatorAdapter adapter, IServiceLocatorStore store) : base(foundation, adapter, store)
        {
            var pipeline = new PostResolutionPipeline(foundation, adapter, store);

            Add(new AdapterPipelineItem(foundation, adapter, store, pipeline));
        }
Esempio n. 38
0
 protected HttpServiceLocator(IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store)
     : base(serviceLocator, store)
 {
     serviceLocator.Register(typeof(PerHttpRequest), typeof(PerHttpRequest));
     Register(Given<HttpContextBase>.ConstructWith(x => new HttpContextWrapper(HttpContext.Current)));
 }
Esempio n. 39
0
 public AdapterPipelineItem(Foundation foundation, IServiceLocatorAdapter serviceLocator,
                            IServiceLocatorStore store, PostResolutionPipeline pipeline)
     : base(foundation, serviceLocator, store)
 {
     this.pipeline = pipeline;
 }
Esempio n. 40
0
 public AdapterPipelineItem(Foundation foundation, IServiceLocatorAdapter serviceLocator,
                            IServiceLocatorStore store, PostResolutionPipeline pipeline)
     : base(foundation, serviceLocator, store)
 {
     this.pipeline = pipeline;
 }
Esempio n. 41
0
 public HttpServiceLocator(IServiceLocatorAdapter serviceLocator, IContextStore store)
     : this(serviceLocator, new HttpServiceLocatorStore(store))
 {
 }
Esempio n. 42
0
 public PostResolutionPipeline(Foundation foundation, IServiceLocatorAdapter adapter, IServiceLocatorStore store)
 {
     Add(new ConditionalPostResolutionPipelineItem(foundation, adapter, store));
     Add(new DefaultPostResolutionPipelineItem(foundation, adapter, store));
 }
Esempio n. 43
0
 public WcfServiceLocator(IServiceLocatorAdapter serviceLocator)
     : base(serviceLocator, new WcfServiceLocatorStore())
 {
 }
 public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
 {
     adapter.Register(registration.GetMappedFromType(), registration.GetMappedToType());
 }
 public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
 {
 }
 public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
 {
     adapter.Register(registration.GetMappedFromType(), registration.GetMappedToType());
 }
Esempio n. 47
0
 protected HttpServiceLocator(IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store)
     : base(serviceLocator, store)
 {
 }
Esempio n. 48
0
 protected BasePipelineItem(Foundation foundation, IServiceLocatorAdapter serviceLocator, IServiceLocatorStore store)
 {
     this.foundation     = foundation;
     this.serviceLocator = serviceLocator;
     this.store          = store;
 }
Esempio n. 49
0
 public abstract void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline);