Ejemplo n.º 1
0
        public GlobalFunqControllerFactory(Container container)
        {
            this.funqBuilder = new ContainerResolveCache(container);

            // Also register all the controller types as transient
            var controllerTypes =
                AppDomain.CurrentDomain
                .GetAssemblies()
                .SelectMany(ass =>
            {
                try
                {
                    return(ass.GetTypes());
                }
                catch (ReflectionTypeLoadException ex)
                {
                    return(ex.Types.Where(t => t != null));
                }
            })
                .Where(type =>
            {
                try
                {
                    return(typeof(IController).IsAssignableFrom(type));
                }
                catch (TypeLoadException ex)
                {
                    return(false);
                }
            })
                .ToList();

            container.RegisterAutoWiredTypes(controllerTypes, ReuseScope.None);
        }
    public FunqDependencyResolver(Container container)
    {
        this.cache = new ContainerResolveCache(container);
        var controllerTypes =
            (from type in Assembly.GetCallingAssembly().GetTypes()
             where typeof(IController).IsAssignableFrom(type)
             select type).ToList();

        container.RegisterAutoWiredTypes(controllerTypes);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Inject alternative container and strategy for resolving Service Types
        /// </summary>
        public ServiceManager(Container container, ServiceController serviceController)
        {
            if (serviceController == null)
                throw new ArgumentNullException("serviceController");

            this.Container = container ?? new Container();
            this.Metadata = serviceController.Metadata; //always share the same metadata
            this.ServiceController = serviceController;

            typeFactory = new ContainerResolveCache(this.Container);
        }
Ejemplo n.º 4
0
        public FunqControllerFactory(Container container)
        {
            this.funqBuilder = new ContainerResolveCache(container);

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

            container.RegisterAutoWiredTypes(controllerTypes);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunqControllerFactory" /> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="assemblies">The assemblies to reflect for IController discovery.</param>
        public FunqControllerFactory(Container container, params Assembly[] assemblies)
        {
            this.funqBuilder = new ContainerResolveCache(container);

            // aggregate the local and external assemblies for processing (unless ignored)
            IEnumerable <Assembly> targetAssemblies = assemblies.Concat(new[] { Assembly.GetCallingAssembly() });

            foreach (var assembly in targetAssemblies)
            {
                // Also register all the controller types as transient
                var controllerTypes =
                    (from type in assembly.GetTypes()
                     where typeof(IController).IsAssignableFrom(type)
                     select type).ToList();

                container.RegisterAutoWiredTypes(controllerTypes);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunqControllerFactory" /> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="assemblies">The assemblies to reflect for IController discovery.</param>
        public FunqControllerFactory(Container container, params Assembly[] assemblies)
		{
			this.funqBuilder = new ContainerResolveCache(container);

            // aggregate the local and external assemblies for processing (unless ignored)
            IEnumerable<Assembly> targetAssemblies = assemblies.Concat(new[] { Assembly.GetCallingAssembly() });

            foreach (var assembly in targetAssemblies)
            {
                // Also register all the controller types as transient
                var controllerTypes =
                    (from type in assembly.GetTypes()
                     where typeof(IController).IsAssignableFrom(type)
                     select type).ToList();

                container.RegisterAutoWiredTypes(controllerTypes);
            }
		}
        public void CreateInstance_throws_on_missing_dependency()
        {
            using (var appHost = new BasicAppHost().Init())
            {
                var services = appHost.Container;
                services.AddTransient <IFoo, Foo>();

                var typeFactory = new ContainerResolveCache(appHost.Container);

                var foo = typeFactory.CreateInstance(services, typeof(IFoo), tryResolve: true);
                Assert.That(foo, Is.Not.Null);

                var bar = typeFactory.CreateInstance(services, typeof(IBar), tryResolve: true);
                Assert.That(bar, Is.Null);

                Assert.Throws <ResolutionException>(() =>
                                                    typeFactory.CreateInstance(services, typeof(IBar), tryResolve: false));
            }
        }
 public FunqValidatorFactory(Container container = null)
 {
     this.funqBuilder = new ContainerResolveCache(container ?? AppHostBase.Instance.Container);
 }
Ejemplo n.º 9
0
 public FunqValidatorFactory(Container container = null)
 {
     this.funqBuilder = new ContainerResolveCache(container ?? HostContext.Container);
 }
Ejemplo n.º 10
0
		public ServiceManager Init()
		{
			typeFactory = new ContainerResolveCache(this.Container);

			this.ServiceController.Register(typeFactory);

			this.Container.RegisterAutoWiredTypes(this.Metadata.ServiceTypes);

		    return this;
		}