Esempio n. 1
0
        /// <summary>
        /// Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>
        /// There is no need to register concrete types such as controllers or
        /// API controllers (unless you want to change the defaults), as Unity
        /// allows resolving a concrete type even if it was not previously
        /// registered.
        /// </remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            var serviceAssemblies    = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("TrainingWebAPI.Service")).ToArray();
            var repositoryAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("TrainingWebAPI.Repository")).ToArray();

            container.RegisterTypes(RegisterTypesScan.GetTypesWithCustomAttribute <BusinessLogicAttribute>(serviceAssemblies), WithMappings.FromMatchingInterface, WithName.Default, WithLifetime.Transient,
                                    getInjectionMembers: t => new InjectionMember[] {
                new Interceptor <InterfaceInterceptor>(),    //Interception technique
                new InterceptionBehavior <BusinessLogicBehaviour>()
            });

            container.RegisterTypes(RegisterTypesScan.GetTypesWithCustomAttribute <DataAccessAttribute>(repositoryAssemblies),
                                    WithMappings.FromMatchingInterface,
                                    WithName.Default,
                                    WithLifetime.Transient,
                                    getInjectionMembers: t => new InjectionMember[] {
                new Interceptor <InterfaceInterceptor>(),    //Interception technique
                new InterceptionBehavior <DataAccessBehaviour>()
            });

            container
            .RegisterType <LogHandler>(new ContainerControlledLifetimeManager())
            .RegisterType <DbContext, EFTrainingEntities>(new ContainerControlledLifetimeManager());


            GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
        }
Esempio n. 2
0
        /// <summary>Registers the type mappings with the Unity container.</summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to
        /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            var myAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("ServiceLayer")).ToArray();

            container.AddNewExtension <Interception>();
            container.RegisterTypes(RegisterTypesScan.GetTypesWithCustomAttribute <RequestReponseAttribute>(myAssemblies),
                                    WithMappings.FromMatchingInterface,
                                    WithName.Default,
                                    WithLifetime.ContainerControlled,
                                    getInjectionMembers: t => new InjectionMember[]
            {
                new Interceptor <InterfaceInterceptor>(),
                new InterceptionBehavior <MvcApplication1.Logging.RequestResponseBehaviour>()
            })
            .RegisterTypes(RegisterTypesScan.GetTypesWithCustomAttribute <DataAccessAttribute>(myAssemblies),
                           WithMappings.FromMatchingInterface,
                           WithName.Default,
                           WithLifetime.Transient
                           );
        }