コード例 #1
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"));
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: ServiceLocator.cs プロジェクト: legendz3/Siege
        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>());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
 {
     adapter.Register(registration.GetMappedFromType(), registration.GetMappedToType());
 }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
 public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
 {
     store.Get <IAwarenessStore>().Add(registration.GetMappedTo());
 }
コード例 #10
0
 public abstract void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline);
コード例 #11
0
        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);
        }