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();

            adapter.RegisterFactoryMethod(mappedFromType, () => pipeline.Execute(mappedFromType));
            RegisterLazy(adapter, mappedFromType, pipeline);

            RegisterContextual(adapter, mappedFromType);

            if (!mappedToType.IsInterface)
            {
                adapter.Register(mappedToType, mappedToType);
                RegisterLazy(adapter, mappedToType, pipeline);
                RegisterContextual(adapter, mappedToType);
            }
        }
Example #3
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)));
 }
 public void Register(IServiceLocatorAdapter adapter, IServiceLocatorStore store, IRegistration registration, ResolutionPipeline pipeline)
 {
     adapter.Register(registration.GetMappedFromType(), registration.GetMappedToType());
 }