internal void Configure(PolicyDefinition policyDefinition)
 {
     if (string.IsNullOrEmpty(this.TypeName))
     {
         policyDefinition.AddMatchingRule(this.Name);
     }
     else
     {
         policyDefinition.AddMatchingRule(
             this.Type,
             this.Name,
             this.Lifetime != null ? this.Lifetime.CreateLifetimeManager() : null,
             this.Injection != null ? this.Injection.GetInjectionMembers() : new InjectionMember[0]);
     }
 }
        private void Setup(TfsDriveParameter dynamicParameters)
        {
            Container = new UnityContainer();
            Container.AddNewExtension <Interception>();

            //Container.RegisterType<IContainer, TfsDrive>(new TransientLifetimeManager(), new InterceptionBehavior<PolicyInjectionBehavior>(), new Interceptor<InterfaceInterceptor>());
            Container.RegisterType <IContainer, TfsDrive>(new TransientLifetimeManager());
            Container.RegisterType <CachingLifetimeManager>(new ContainerControlledLifetimeManager());

            if (null != dynamicParameters.DataService)
            {
                Container.RegisterInstance(dynamicParameters.DataService);
            }
            else
            {
                Container.RegisterType <ITfsDataService, TfsRestDataService>(new ContainerControlledLifetimeManager(), new InjectionConstructor(
                                                                                 new InjectionParameter <string>(dynamicParameters.Url),
                                                                                 new InjectionParameter <string>(dynamicParameters.AccessToken)
                                                                                 ), new InterceptionBehavior <PolicyInjectionBehavior>(), new Interceptor <InterfaceInterceptor>());
            }

            PolicyDefinition loggingPolicy = Container.Configure <Interception>().AddPolicy("logging");

            loggingPolicy.AddMatchingRule <AssemblyMatchingRule>(new InjectionConstructor(new InjectionParameter(GetType().Assembly.FullName)));
            loggingPolicy.AddCallHandler <LoggingCallHandler>(new ContainerControlledLifetimeManager(), new InjectionConstructor());
            loggingPolicy.AddCallHandler <PerformanceMeasurementHandler>(new ContainerControlledLifetimeManager(), new InjectionConstructor());
            loggingPolicy.AddCallHandler <CachingCallHandler>(Container.Resolve <CachingLifetimeManager>(), new InjectionConstructor());

            TfsDataService = Container.Resolve <ITfsDataService>();
        }
Esempio n. 3
0
        internal void Configure(IUnityContainer container, PolicyDefinition policyDefinition)
        {
            if (string.IsNullOrEmpty(TypeName))
            {
                policyDefinition.AddMatchingRule(Name);
            }
            else
            {
                Type            matchingRuleType = TypeResolver.ResolveType(TypeName);
                LifetimeManager lifetime         = Lifetime.CreateLifetimeManager();
                IEnumerable <InjectionMember> injectionMembers =
                    Injection.SelectMany(
                        element => element.GetInjectionMembers(container, typeof(IMatchingRule), matchingRuleType, Name));

                policyDefinition.AddMatchingRule(matchingRuleType, lifetime, injectionMembers.ToArray());
            }
        }
 static H容器()
 {
     _IUnityContainer  = new UnityContainer();
     _Interception     = _IUnityContainer.AddNewExtension <Interception>().Configure <Interception>();
     _PolicyDefinition = _Interception.AddPolicy("MyPolicy");
     _PolicyDefinition.AddMatchingRule <AlwaysMatchingRule>();
     _PolicyDefinition.AddCallHandler <LoggerCallHandler>(new ContainerControlledLifetimeManager());
 }
Esempio n. 5
0
        internal void Configure(IUnityContainer container, PolicyDefinition policyDefinition)
        {
            if (string.IsNullOrEmpty(TypeName))
            {
                policyDefinition.AddMatchingRule(Name);
            }
            else
            {
                Type matchingRuleType = TypeResolver.ResolveType(TypeName);
                LifetimeManager lifetime = Lifetime.CreateLifetimeManager();
                IEnumerable<InjectionMember> injectionMembers =
                    Injection.SelectMany(
                        element => element.GetInjectionMembers(container, typeof(IMatchingRule), matchingRuleType, Name));

                policyDefinition.AddMatchingRule(matchingRuleType, lifetime, injectionMembers.ToArray());
            }
        }
Esempio n. 6
0
        public void TestInitialize()
        {
            Container = new UnityContainer();
            Container.AddNewExtension <Interception>();

            Container.RegisterType <ITenantStore, TenantStore>(new InterceptionBehavior <PolicyInjectionBehavior>(), new Interceptor <InterfaceInterceptor>());
            Container.RegisterType <ISurveyStore, SurveyStore>(new InterceptionBehavior <PolicyInjectionBehavior>(), new Interceptor <InterfaceInterceptor>());

            InjectionProperty first  = new InjectionProperty("Order", 1);
            InjectionProperty second = new InjectionProperty("Order", 2);

            PolicyDefinition loggingPolicy = Container.Configure <Interception>().AddPolicy("logging");

            loggingPolicy.AddMatchingRule <AssemblyMatchingRule>(new InjectionConstructor(new InjectionParameter(GetType().Assembly.FullName)));
            loggingPolicy.AddCallHandler <LoggingCallHandler>(new ContainerControlledLifetimeManager(), new InjectionConstructor(), first);

            PolicyDefinition cachingPolicy = Container.Configure <Interception>().AddPolicy("caching");

            cachingPolicy.AddMatchingRule <AssemblyMatchingRule>(new InjectionConstructor(new InjectionParameter(GetType().Assembly.FullName)));
            cachingPolicy.AddCallHandler <CachingCallHandler>(new ContainerControlledLifetimeManager(), new InjectionConstructor(), second);
        }
Esempio n. 7
0
        //************************************************************************
        /// <summary>
        /// Windowsアプリケーションの初期設定
        /// </summary>
        //************************************************************************
        public static bool InitialSetting()
        {
            // 集約例外ハンドラの設定
            Application.ThreadException += Application_ThreadException;

            // 表示スタイルの設定
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.CurrentCulture = new CultureInfo("ja-JP", false);

            #region Unity設定
            // Unityコンテナ取得
            var container = UnityContainerManager.Container;

            // Interceptionを拡張
            container.AddNewExtension <Interception>();

            // Interceptionの設定
            PolicyDefinition policyDef = container.Configure <Interception>().AddPolicy("Client");
            policyDef.AddMatchingRule(new CustomAttributeMatchingRule(typeof(ShowWaitingAttribute), true));

            // Injection設定
            foreach (string file in
                     Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "Common*.dll", SearchOption.AllDirectories))
            {
                var asm = Assembly.LoadFile(file);

                // IBaseServiceを継承するInterfaceを登録
                if (Properties.Settings.Default.ServiceCall == "Local")
                {
                    container.RegisterTypes(
                        asm.ExportedTypes.Where(t => t.IsClass == true && t.GetInterfaces().Contains(typeof(IBaseService))),
                        WithMappings.FromMatchingInterface,
                        //getLifetimeManager: t => new PerResolveLifetimeManager(),
                        getInjectionMembers: t => new InjectionMember[]
                    {
                        new Interceptor <InterfaceInterceptor>(),
                        new InterceptionBehavior <PolicyInjectionBehavior>()
                    });
                }
                else
                {
                    container.RegisterTypes(
                        asm.ExportedTypes.Where(t => t.IsInterface == true && t.GetInterfaces().Contains(typeof(IBaseService))),
                        getInjectionMembers: t => new InjectionMember[]
                    {
                        new InjectionFactory(c => ServiceUtil.GetServiceProxy(t)),
                        new Interceptor <InterfaceInterceptor>(),
                        new InterceptionBehavior <PolicyInjectionBehavior>(),
                        new InterceptionBehavior <ServiceCallBehavior>()
                    });
                }
            }

            // BaseFormを継承するクラスを登録
            container.RegisterTypes(
                AllClasses.FromLoadedAssemblies().Where(c => c.IsSubclassOf(typeof(BaseForm))),
                getInjectionMembers: t => new InjectionMember[]
            {
                new Interceptor <VirtualMethodInterceptor>(),
                new InterceptionBehavior <PolicyInjectionBehavior>()
            });

            // Local設定の追加
            if (Properties.Settings.Default.ServiceCall == "Local")
            {
                // TransactionAttributeを登録
                var t = Type.GetType("Common.Unity.UseTransactionAttribute, CommonService");
                policyDef.AddMatchingRule(new CustomAttributeMatchingRule(t, true));

                // DbContextを登録
                var t2 = Type.GetType("Common.DataAccess.BaseDbContext, CommonService");
                container.RegisterType(t2, new PerResolveLifetimeManager());
            }
            #endregion

            // 未認証の場合は、ログイン実行
            if (!Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                InformationManager.ClientInfo = new ClientInformation();

                using (var login = container.Resolve <LoginDialog>())
                {
                    // ログイン画面を表示してログインを実行
                    var result = login.ShowDialog();

                    if (result == DialogResult.Abort && login.Exception != null)
                    {
                        // スロー
                        throw login.Exception;
                    }
                    else if (result != DialogResult.OK)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }