예제 #1
0
        /// <summary>
        /// Alias for RegisterAutoWiredAs
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void RegisterAs <T, TAs>()
            where T : TAs
        {
            var autoWired = new ExpressionTypeFunqContainer(this);

            autoWired.RegisterAs <T, TAs>();
        }
        public static ITypeFactory GetAutoWiredFunqTypeFactory()
        {
            var container = GetContainerWithDependencies();

            var typeFactory = new ExpressionTypeFunqContainer(container);
            typeFactory.RegisterTypes(typeof(StoreCustomersService), typeof(GetCustomerService));

            return typeFactory;
        }
예제 #3
0
        public static ITypeFactory GetAutoWiredFunqTypeFactory()
        {
            var container = GetContainerWithDependencies();

            var typeFactory = new ExpressionTypeFunqContainer(container);

            typeFactory.RegisterTypes(typeof(StoreCustomersService), typeof(GetCustomerService));

            return(typeFactory);
        }
예제 #4
0
        public void Init()
        {
            this.Container = new Container();

            var typeFactory = new ExpressionTypeFunqContainer(this.Container);

            this.ServiceController.Register(typeFactory, assembliesWithServices);

            typeFactory.RegisterTypes(this.ServiceController.ServiceTypes);
        }
        public void With_Funq_and_Expressions()
        {
            var container = new Container();
            container.Register<IFoo>(c => new Foo());
            container.Register<IBar>(c => new Bar());

            var funqlet = new ExpressionTypeFunqContainer(container);
            funqlet.RegisterTypes(typeof(AutoWireService));

            Console.WriteLine("With_Funq_and_Expressions(): {0}", Measure(() => container.Resolve<AutoWireService>(), Times));
        }
 /// <summary>
 /// Auto-scans the provided assemblies for a <see cref="IValidator"/>
 /// and registers it in the provided IoC container.
 /// </summary>
 /// <param name="container">The IoC container</param>
 /// <param name="assemblies">The assemblies to scan for a validator</param>
 public static void RegisterValidators(this Container container, params Assembly[] assemblies)
 {
     var autoWire = new ExpressionTypeFunqContainer(container);
     foreach (var assembly in assemblies)
     {
         foreach (var validator in assembly.GetTypes()
             .Where(t => t.IsOrHasGenericInterfaceTypeOf(typeof(IValidator<>))))
         {
             RegisterValidator(autoWire, validator);
         }
     }
 }
예제 #7
0
        public void With_Funq_and_Expressions()
        {
            var container = new Container();

            container.Register <IFoo>(c => new Foo());
            container.Register <IBar>(c => new Bar());

            var funqlet = new ExpressionTypeFunqContainer(container);

            funqlet.RegisterTypes(typeof(AutoWireService));

            Console.WriteLine("With_Funq_and_Expressions(): {0}", Measure(() => container.Resolve <AutoWireService>(), Times));
        }
        private static void RegisterValidator(ExpressionTypeFunqContainer autoWire, Type validator)
        {
            var baseType = validator.BaseType;
            while (!baseType.IsGenericType)
            {
                baseType = baseType.BaseType;
            }

            var dtoType = baseType.GetGenericArguments()[0];
            var validatorType = typeof (IValidator<>).MakeGenericType(dtoType);

            autoWire.RegisterType(validator, validatorType);
        }
예제 #9
0
        /// <summary>
        /// Auto-scans the provided assemblies for a <see cref="IValidator"/>
        /// and registers it in the provided IoC container.
        /// </summary>
        /// <param name="container">The IoC container</param>
        /// <param name="assemblies">The assemblies to scan for a validator</param>
        public static void RegisterValidators(this Container container, params Assembly[] assemblies)
        {
            var autoWire = new ExpressionTypeFunqContainer(container);

            foreach (var assembly in assemblies)
            {
                foreach (var validator in assembly.GetTypes()
                         .Where(t => t.IsOrHasGenericInterfaceTypeOf(typeof(IValidator <>))))
                {
                    RegisterValidator(autoWire, validator);
                }
            }
        }
        public FunqControllerFactory(Container container)
        {
            this.funqBuilder = new ExpressionTypeFunqContainer(container) {
                Scope = ReuseScope.None //don't re-use instances
            };

            // Also register all the controller types as transient
            var controllerTypes =
                from type in Assembly.GetExecutingAssembly().GetTypes()
                where typeof(IController).IsAssignableFrom(type)
                select type;

            funqBuilder.RegisterTypes(controllerTypes);
        }
예제 #11
0
        private static void RegisterValidator(ExpressionTypeFunqContainer autoWire, Type validator)
        {
            var baseType = validator.BaseType;

            while (!baseType.IsGenericType)
            {
                baseType = baseType.BaseType;
            }

            var dtoType       = baseType.GetGenericArguments()[0];
            var validatorType = typeof(IValidator <>).MakeGenericType(dtoType);

            autoWire.RegisterType(validator, validatorType);
        }
예제 #12
0
        public FunqControllerFactory(Container container)
        {
            this.funqBuilder = new ExpressionTypeFunqContainer(container)
            {
                Scope = ReuseScope.None                 //don't re-use instances
            };

            // Also register all the controller types as transient
            var controllerTypes =
                from type in Assembly.GetExecutingAssembly().GetTypes()
                where typeof(IController).IsAssignableFrom(type)
                select type;

            funqBuilder.RegisterTypes(controllerTypes);
        }
예제 #13
0
        public void Can_AutoWire_types_dynamically_with_expressions()
        {
            var serviceType = typeof(AutoWireService);

            var container = new Container();
            container.Register<IFoo>(c => new Foo());
            container.Register<IBar>(c => new Bar());

            var typeContainer = new ExpressionTypeFunqContainer(container);
            typeContainer.RegisterTypes(serviceType);

            var service = container.Resolve<AutoWireService>();

            Assert.That(service.Foo, Is.Not.Null);
            Assert.That(service.Bar, Is.Not.Null);
        }
예제 #14
0
        public void Can_AutoWire_types_dynamically_with_expressions()
        {
            var serviceType = typeof(AutoWireService);

            var container = new Container();

            container.Register <IFoo>(c => new Foo());
            container.Register <IBar>(c => new Bar());

            var typeContainer = new ExpressionTypeFunqContainer(container);

            typeContainer.RegisterTypes(serviceType);

            var service = container.Resolve <AutoWireService>();

            Assert.That(service.Foo, Is.Not.Null);
            Assert.That(service.Bar, Is.Not.Null);
        }
예제 #15
0
        public void Init()
        {
            var typeFactory = new ExpressionTypeFunqContainer(this.Container);

            this.ServiceController.Register(typeFactory);

            this.ServiceOperations = new ServiceOperations(this.ServiceController.OperationTypes);
            this.AllServiceOperations = new ServiceOperations(this.ServiceController.AllOperationTypes);

            typeFactory.RegisterTypes(this.ServiceController.ServiceTypes);
        }
예제 #16
0
        /// <summary>
        /// Register an autowired dependency
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void RegisterAutoWired <T>()
        {
            var autoWired = new ExpressionTypeFunqContainer(this);

            autoWired.Register <T>();
        }