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 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);
        }
示例#3
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);
        }
        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);
        }
示例#6
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);
        }
示例#7
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);
        }
        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);
        }
示例#12
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);
        }