public void Install( IUnityContainer container, BootstrapConventions conventions, IEnumerable<Type> allTypes )
		{
			allTypes
				.Where( t => conventions.IsService( t ) && !conventions.IsExcluded( t ) )
				.Select( type =>
				{
					return new
					{
						Contracts = conventions.SelectServiceContracts( type ),
						TypeTo = type
					};
				} )
				.ForEach( r =>
				{
					/*
					 * questa è una magagna perchè Unity non ci consente la registrazione dei forwarder
					 * ed è un macello perché anche se riuscissimo ad iniettare una policy che "conosce"
					 * i forwarder ci scontriamo con il fatto che le build-key, in apparenza, infilate nella
					 * ContainerRegistration vengono risolte immediatamente all'avvio e non on-demend, ergo
					 * non abbiamo come in Castle il concetto di "attesa" per le dipendenze.
					 */
					container.RegisterType( r.TypeTo, r.TypeTo,
						new ContainerControlledLifetimeManager(),
						new CandidateConstructorSelector( container ) );

					foreach ( var contract in r.Contracts )
					{
						container.RegisterType( contract,
							new InjectionFactory( c =>
							{
								return c.Resolve( r.TypeTo );
							} ) );
					}
				} );
		}
        public void Install(IUnityContainer container, BootstrapConventions conventions, IEnumerable <Type> allTypes)
        {
            allTypes
            .Where(t => conventions.IsService(t) && !conventions.IsExcluded(t))
            .Select(type =>
            {
                return(new
                {
                    Contracts = conventions.SelectServiceContracts(type),
                    TypeTo = type
                });
            })
            .ForEach(r =>
            {
                /*
                 * questa è una magagna perchè Unity non ci consente la registrazione dei forwarder
                 * ed è un macello perché anche se riuscissimo ad iniettare una policy che "conosce"
                 * i forwarder ci scontriamo con il fatto che le build-key, in apparenza, infilate nella
                 * ContainerRegistration vengono risolte immediatamente all'avvio e non on-demend, ergo
                 * non abbiamo come in Castle il concetto di "attesa" per le dipendenze.
                 */
                container.RegisterType(r.TypeTo, r.TypeTo,
                                       new ContainerControlledLifetimeManager(),
                                       new CandidateConstructorSelector(container));

                foreach (var contract in r.Contracts)
                {
                    container.RegisterType(contract,
                                           new InjectionFactory(c =>
                    {
                        return(c.Resolve(r.TypeTo));
                    }));
                }
            });
        }
		public void Configure( ContainerBuilder builder, BootstrapConventions conventions, IEnumerable<Assembly> assemblies )
		{
			var types = assemblies.SelectMany( a => a.GetTypes() ).ToArray();

			types.Where( t => conventions.IsViewModel( t ) && !conventions.IsExcluded( t ) )
				.Select( t => new
				{
					Contracts = conventions.SelectViewModelContracts( t ),
					Implementation = t
				} )
				.ForEach( r =>
				{
					if ( conventions.IsShellViewModel( r.Contracts, r.Implementation ) )
					{
						builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).SingleInstance();
					}
					else
					{
						builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).InstancePerDependency();
					}
				} );

			types.Where( t => conventions.IsView( t ) && !conventions.IsExcluded( t ) )
				.Select( t => new
				{
					Contracts = conventions.SelectViewContracts( t ),
					Implementation = t
				} )
				.ForEach( r =>
				{
					if ( conventions.IsShellView( r.Contracts, r.Implementation ) )
					{
						builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).SingleInstance();
					}
					else
					{
						builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).InstancePerDependency();
					}
				} );
		}
Esempio n. 4
0
        public void Install(IUnityContainer container, BootstrapConventions conventions, IEnumerable <Type> allTypes)
        {
            allTypes
            .Where(t => conventions.IsViewModel(t) && !conventions.IsExcluded(t))
            .Select(type => new
            {
                TypeFrom = conventions.SelectViewModelContracts(type).Single(),
                TypeTo   = type
            })
            .ForEach(r =>
            {
                if (conventions.IsShellViewModel(new[] { r.TypeFrom }, r.TypeTo))
                {
                    container.RegisterType(r.TypeFrom, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container));
                }
                else
                {
                    container.RegisterType(r.TypeFrom, r.TypeTo, new TransientLifetimeManager(), new CandidateConstructorSelector(container));
                }
            });

            allTypes
            .Where(t => conventions.IsView(t) && !conventions.IsExcluded(t))
            .Select(type => new
            {
                TypeFrom = conventions.SelectViewContracts(type).Single(),
                TypeTo   = type
            })
            .ForEach(r =>
            {
                if (conventions.IsShellView(new[] { r.TypeFrom }, r.TypeTo))
                {
                    container.RegisterType(r.TypeFrom, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector(container));
                }
                else
                {
                    container.RegisterType(r.TypeFrom, r.TypeTo, new TransientLifetimeManager(), new CandidateConstructorSelector(container));
                }
            });
        }
		public void Install( IUnityContainer container, BootstrapConventions conventions, IEnumerable<Type> allTypes )
		{
			allTypes
				.Where( t => conventions.IsViewModel( t ) && !conventions.IsExcluded( t ) )
				.Select( type => new
				{
					TypeFrom = conventions.SelectViewModelContracts( type ).Single(),
					TypeTo = type
				} )
				.ForEach( r =>
				{
					if ( conventions.IsShellViewModel( new[] { r.TypeFrom }, r.TypeTo ) )
					{
						container.RegisterType( r.TypeFrom, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector( container ) );
					}
					else
					{
						container.RegisterType( r.TypeFrom, r.TypeTo, new TransientLifetimeManager(), new CandidateConstructorSelector( container ) );
					}
				} );

			allTypes
				.Where( t => conventions.IsView( t ) && !conventions.IsExcluded( t ) )
				.Select( type => new
				{
					TypeFrom = conventions.SelectViewContracts( type ).Single(),
					TypeTo = type
				} )
				.ForEach( r =>
				{
					if ( conventions.IsShellView( new[] { r.TypeFrom }, r.TypeTo ) )
					{
						container.RegisterType( r.TypeFrom, r.TypeTo, new ContainerControlledLifetimeManager(), new CandidateConstructorSelector( container ) );
					}
					else
					{
						container.RegisterType( r.TypeFrom, r.TypeTo, new TransientLifetimeManager(), new CandidateConstructorSelector( container ) );
					}
				} );
		}
        public void Configure(ContainerBuilder builder, BootstrapConventions conventions, IEnumerable <Assembly> assemblies)
        {
            var types = assemblies.SelectMany(a => a.GetTypes()).ToArray();

            types.Where(t => conventions.IsViewModel(t) && !conventions.IsExcluded(t))
            .Select(t => new
            {
                Contracts      = conventions.SelectViewModelContracts(t),
                Implementation = t
            })
            .ForEach(r =>
            {
                if (conventions.IsShellViewModel(r.Contracts, r.Implementation))
                {
                    builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).SingleInstance();
                }
                else
                {
                    builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).InstancePerDependency();
                }
            });

            types.Where(t => conventions.IsView(t) && !conventions.IsExcluded(t))
            .Select(t => new
            {
                Contracts      = conventions.SelectViewContracts(t),
                Implementation = t
            })
            .ForEach(r =>
            {
                if (conventions.IsShellView(r.Contracts, r.Implementation))
                {
                    builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).SingleInstance();
                }
                else
                {
                    builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).InstancePerDependency();
                }
            });
        }
		public void Configure( ContainerBuilder builder, BootstrapConventions conventions, IEnumerable<Assembly> assemblies )
		{
			assemblies.SelectMany( a => a.GetTypes() )
				.Where( t => conventions.IsMessageHandler( t ) && !conventions.IsExcluded( t ) )
				.Select( t => new
				{
					Contracts = conventions.SelectMessageHandlerContracts( t ),
					Implementation = t
				} )
				.ForEach( r =>
				{
					builder.RegisterType( r.Implementation ).As( r.Contracts.ToArray() ).SingleInstance();
				} );
		}
Esempio n. 8
0
 public void Configure(ContainerBuilder builder, BootstrapConventions conventions, IEnumerable <Assembly> assemblies)
 {
     assemblies.SelectMany(a => a.GetTypes())
     .Where(t => conventions.IsMessageHandler(t) && !conventions.IsExcluded(t))
     .Select(t => new
     {
         Contracts      = conventions.SelectMessageHandlerContracts(t),
         Implementation = t
     })
     .ForEach(r =>
     {
         builder.RegisterType(r.Implementation).As(r.Contracts.ToArray()).SingleInstance();
     });
 }