当前位置: 首页>>代码示例>>C#>>正文


C# IUnityContainer.Configure方法代码示例

本文整理汇总了C#中IUnityContainer.Configure方法的典型用法代码示例。如果您正苦于以下问题:C# IUnityContainer.Configure方法的具体用法?C# IUnityContainer.Configure怎么用?C# IUnityContainer.Configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUnityContainer的用法示例。


在下文中一共展示了IUnityContainer.Configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureContainer

        protected override void ConfigureContainer(IUnityContainer container)
        {
            BetamaxSettings settings = null;

            var recorder = container.Configure<BetamaxRecorder>();
            if (recorder != null)
            {
                settings = recorder.Settings;
            }
            else
            {
                var player = container.Configure<BetamaxPlayer>();
                if (player != null)
                {
                    settings = player.Settings;
                }
            }

            if (settings == null)
                return;

            if (!string.IsNullOrEmpty(Tapes))
            {
                settings.TapesLocation = Tapes;
            }

            InterestingInterfaces.ForEach(interesting => interesting.ConfigureContainer(settings));
        }
开发者ID:chakming,项目名称:Betamax.Net,代码行数:28,代码来源:BetamaxElement.cs

示例2: RegisterTypes

    public static void RegisterTypes(IUnityContainer container)
    {
        string[] assemblyNameParts = Assembly.GetExecutingAssembly().GetName().Name.Split('.');
        string assemblyPrefix = string.Join(".", assemblyNameParts, 0, 1);

        container.AddNewExtension<Interception>(); 

        Predicate<Type> intercept = (t) =>
        {
            var interceptionConfiguration = container.Configure<Interception>();
            if (t.IsConcrete() && !t.IsSealed && hasAttribute(t, typeof(LogAttribute)))
            {
                interceptionConfiguration.SetDefaultInterceptorFor(t, new VirtualMethodInterceptor());
            }
            return true;
        };

        Predicate<Assembly> includeAssembly = (a) =>
        {
            var assemblyName = a.GetName().Name;
            return assemblyName.StartsWith(assemblyPrefix) && (assemblyName.Contains("Business")  || assemblyName.Contains("Data"));
        };

        container.Configure(c =>
        {
            c.Scan(scan =>
            {
                scan.AssembliesInBaseDirectory(a => includeAssembly(a));
                scan.Include(t => intercept(t));
                scan.WithNamingConvention();
            });

            c.Configure<IDatabaseControlContext>().Using<HttpContextLifetimeManager<IDatabaseControlContext>>();
        });
    }
开发者ID:vvilella,项目名称:Telos.Admin,代码行数:35,代码来源:UnityConfig.cs

示例3: RegisterDependencies

        /// <summary>
        /// Additionally configures unity container with classes in Database access project
        /// </summary>
        /// <param name="container">Unity container instance</param>
        public static void RegisterDependencies(IUnityContainer container)
        {
            container.RegisterType<IServiceBehavior, UmaConnNHibernateBehavior>("nHibernate");

            container.RegisterInstance<ISessionFactory>(UmaConnNhibernateFactory.Instance, new ContainerControlledLifetimeManager());
            container.RegisterType<ISession>(
                new HierarchicalLifetimeManager(),
                new InjectionFactory(c => container.Resolve<ISessionFactory>().OpenSession()));

            container.RegisterType<IUmaMasterDataService, UmaMasterDataService>();
            container.RegisterType<ICallHandler, UmaConnTransactionHandler>("TransactionHandler");

            container.AddNewExtension<Interception>();
            container.Configure<Interception>().SetInterceptorFor<UmaMasterDataService>(new TransparentProxyInterceptor());

            // These extensions will handle cases where
            // ILog is resolved as Property with [Dependency] attribute.
            // Will create Logger with name of resolving Type.
            // http://blog.baltrinic.com/software-development/dotnet/log4net-integration-with-unity-ioc-container
            container
                .AddNewExtension<BuildTracking>()
                .AddNewExtension<LogCreation>();

            // DO NOT DELETE THIS CODE UNLESS WE NO LONGER REQUIRE ASSEMBLY NLOG.EXTENDED!!!
            var dummyCall = typeof(NLog.Web.NLogHttpModule);
            var ok = dummyCall.Assembly.CodeBase;
        }
开发者ID:targitaj,项目名称:m3utonetpaleyerxml,代码行数:31,代码来源:DependencyConfig.cs

示例4: RegisterInterceptor

 /// <summary>
 /// Actually register the interceptor against this type.
 /// </summary>
 /// <param name="container">Container to configure.</param>
 /// <param name="interceptor">interceptor to register.</param>
 internal override void RegisterInterceptor(IUnityContainer container, IInterceptor interceptor)
 {
     var typeInterceptor = interceptor as ITypeInterceptor;
     if (typeInterceptor != null)
     {
         container.Configure<Interception>().SetInterceptorFor(
             this.ResolvedType, this.Name,
             typeInterceptor);
     }
     else
     {
         container.Configure<Interception>().SetInterceptorFor(
             this.ResolvedType, this.Name,
             (IInstanceInterceptor)interceptor);
     }
 }
开发者ID:kangkot,项目名称:unity,代码行数:21,代码来源:KeyElement.cs

示例5: InitializeContainer

 private void InitializeContainer()
 {
     container = new UnityContainer();
     container.AddNewExtension<Interception>();
     container.RegisterType<BusinessLogic.BankAccount>(
         new InterceptionBehavior<PolicyInjectionBehavior>(),
         new Interceptor<TransparentProxyInterceptor>());
     container.Configure<Interception>()
         .AddPolicy("policy-updates")
             .AddMatchingRule<TypeMatchingRule>(
                 new InjectionConstructor(
                     new InjectionParameter(typeof(BusinessLogic.BankAccount))))
             .AddMatchingRule<MemberNameMatchingRule>(
                 new InjectionConstructor(
                     new InjectionParameter(new string[] { "Deposit", "Withdraw" })))
             .AddCallHandler<TraceCallHandler>(
                 new ContainerControlledLifetimeManager(),
                 new InjectionConstructor(
                     new TraceSource("interception-updates")))
         .Interception
         .AddPolicy("policy-query")
             .AddMatchingRule<TypeMatchingRule>(
                 new InjectionConstructor(
                     new InjectionParameter(typeof(BusinessLogic.BankAccount))))
             .AddMatchingRule<MemberNameMatchingRule>(
                 new InjectionConstructor("GetCurrentBalance"))
             .AddCallHandler<TraceCallHandler>(
                 new ContainerControlledLifetimeManager(),
                 new InjectionConstructor(
                     new TraceSource("interception-queries")));
 }
开发者ID:kanpinar,项目名称:unity3.1th,代码行数:31,代码来源:MainForm.cs

示例6: IsTypeRegistered

        /// <summary>
        /// Evaluates if a specified type was registered in the container.
        /// </summary>
        /// <param name="container">The container to check if the type was registered in.</param>
        /// <param name="type">The type to check if it was registered.</param>
        /// <returns><see langword="true" /> if the <paramref name="type"/> was registered with the container.</returns>
        /// <remarks>
        /// In order to use this extension, you must first call <see cref="IUnityContainer.AddNewExtension{TExtension}"/> 
        /// and specify <see cref="UnityContainerExtension"/> as the extension type.
        /// </remarks>
        public static bool IsTypeRegistered(IUnityContainer container, Type type)
        {
            var extension = container.Configure<UnityIsTypeRegisteredExtension>();

            // The extension wasn't registered in the container, so we can't determine
            // if the type is registered or not.
            if (extension == null) return false;

            return extension.Context.Policies.Get<IBuildKeyMappingPolicy>(new NamedTypeBuildKey(type)) != null;
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:20,代码来源:UnityIsTypeRegisteredExtension.cs

示例7: IsTypeRegistered

 /// <summary>
 /// Evaluates if a specified type was registered in the container.
 /// </summary>
 /// <param name="container">The container to check if the type was registered in.</param>
 /// <param name="type">The type to check if it was registered.</param>
 /// <returns><see langword="true" /> if the <paramref name="type"/> was registered with the container.</returns>
 /// <remarks>
 /// In order to use this extension, you must first call <see cref="UnityContainerExtensions.AddNewExtension{TExtension}"/> 
 /// and specify <see cref="UnityContainerExtension"/> as the extension type.
 /// </remarks>
 public static bool IsTypeRegistered(IUnityContainer container, Type type)
 {
     var extension = container.Configure<UnityBootstrapperExtension>();
     if (extension == null) {
         //Extension was not added to the container.
         return false;
     }
     var policy = extension.Context.Policies.Get<IBuildKeyMappingPolicy>(new NamedTypeBuildKey(type));
     return policy != null;
 }
开发者ID:michaelnero,项目名称:SignalR-demos,代码行数:20,代码来源:UnityBootstrapperExtension.cs

示例8: Setup

        public void Setup()
        {
            container = new UnityContainer();
            container.RegisterType<ICallHandler, MyCallHandler>("MyHandler", new ContainerControlledLifetimeManager());
            container.AddNewExtension<Interception>();

            container.Configure<Interception>()
                .AddPolicy("My Policy")
                    .AddMatchingRule(new AlwaysMatchingRule())
                    .AddCallHandler("MyHandler");
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:11,代码来源:EventInterceptionFixture.cs

示例9: IsRegistered

        public static bool IsRegistered(IUnityContainer container, Type type)
        {
            InternalUnityExtension extension = container.Configure<InternalUnityExtension>();
            IBuildKeyMappingPolicy policy = null;

            if (extension != null)
            {
                policy = extension.Context.Policies.Get<IBuildKeyMappingPolicy>(new NamedTypeBuildKey(type));
            }

            return policy != null;
        }
开发者ID:GTuritto,项目名称:AspNetMvcExtensibility,代码行数:12,代码来源:InternalUnityExtension.cs

示例10: UnityProvider

 public UnityProvider(IDictionary<Type, object> map, int dbRetries, int dbSleepSeconds)
 {
     IMatchingRule alwaysMatch = new AlwaysMatchingRule();
     _map = map;
     _container = new UnityContainer();
     _retries = dbRetries;
     _sleepSeconds = dbSleepSeconds;
     IDictionary<Type, RetryOrHandleExceptionDelgate> exceptionTranslators = GetExceptionTranslators(map);            
     _container.AddNewExtension<Interception>();
     Interception inter = _container.Configure<Interception>();
     if (inter == null)
     {
         Trace.WriteLine("No interception");
     }            
     PolicyDefinition definition = inter.AddPolicy("DbRetry");
     if (definition == null)
     {
         Trace.WriteLine("No policy definition 0");
     }
     if (definition.AddMatchingRule(alwaysMatch) == null)
     {
         Trace.WriteLine("No policy definition 1");
     }
     _interceptor = new DbRetryInterceptor(dbRetries, dbSleepSeconds, exceptionTranslators);
     if (definition.AddCallHandler(_interceptor) == null)
     {
         Trace.WriteLine("No policy definition 2");
     }                            
     IInstanceInterceptor _instanceInterceptor = new InterfaceInterceptor();
     foreach (KeyValuePair<Type, object> entry in map)
     {
         _container.RegisterInstance(entry.Key, entry.Value);
         if (entry.Key.IsInterface)
         {
             _container.Configure<Interception>().SetInterceptorFor(entry.Key, _instanceInterceptor);
         }
     }
 }
开发者ID:amalapannuru,项目名称:RFC,代码行数:38,代码来源:UnityProvider.cs

示例11: RegisterNHibernateStuff

        private void RegisterNHibernateStuff(IUnityContainer container)
        {
            container.RegisterInstance<ISessionFactory>(CreateSessionFactory());
            container.RegisterType<ISession>(new RequestContextLifeTimeManager(typeof(ISession)));

            container.Configure<StaticFactoryExtension>()
                     .RegisterFactory<ISession>(c => c.Resolve<ISessionFactory>().GetCurrentSession());

            container.RegisterType<IRepository, NHibernateRepository>();
            container.RegisterType<IUnitOfWorkProvider, NHibernateUnitOfWorkProvider>();
        }
开发者ID:mikeminutillo,项目名称:Ozmosis,代码行数:11,代码来源:OzmosisApplication.cs

示例12: ConfigureNHibernateRepositories

      private static void ConfigureNHibernateRepositories(IUnityContainer container)
      {
         container.RegisterType<ILocationRepository, LocationRepository>();
         container.RegisterType<ICargoRepository, CargoRepository>();

         container.AddNewExtension<Interception>();
         container.Configure<Interception>()
            .SetInterceptorFor<IBookingService>(new InterfaceInterceptor())
            .SetInterceptorFor<IHandlingEventService>(new InterfaceInterceptor())
            .AddPolicy("Transactions")
            .AddCallHandler<TransactionCallHandler>()
            .AddMatchingRule(new AssemblyMatchingRule("DDDSample.Application"));
      }
开发者ID:ssajous,项目名称:DDDSample.Net,代码行数:13,代码来源:Global.asax.cs

示例13: RegisterIfMissing

 /// <summary>
 /// Helper method that registers <see cref="TypeRegistrationTrackerExtension"/> extensions
 /// in the Unity container if not previously registered.
 /// </summary>
 /// <param name="container">Target container.</param>
 public static void RegisterIfMissing(IUnityContainer container)
 {
     var extension = container.Configure<TypeRegistrationTrackerExtension>();
     if (extension == null)
         container.AddNewExtension<TypeRegistrationTrackerExtension>();
 }
开发者ID:jbogard,项目名称:MefContrib,代码行数:11,代码来源:TypeRegistrationTrackerExtension.cs

示例14: ConfigureContainer

        internal void ConfigureContainer(IUnityContainer container)
        {
            PolicyDefinition policyDefinition = container.Configure<Interception>().AddPolicy(this.Name);
            foreach (var matchingRuleElement in this.MatchingRules)
            {
                matchingRuleElement.Configure(container, policyDefinition);
            }

            foreach (var callHandlerElement in this.CallHandlers)
            {
                callHandlerElement.Configure(container, policyDefinition);
            }
        }
开发者ID:kangkot,项目名称:unity,代码行数:13,代码来源:PolicyElement.cs

示例15: AddExceptionPolicy

 void AddExceptionPolicy(IUnityContainer factory,
                         string exceptionPolicyName,
                         params IMatchingRule[] rules)
 {
     var policy = factory.Configure<Interception>().AddPolicy("Noop");
     foreach (var rule in rules)
     {
         policy.AddMatchingRule(rule);
     }
     policy.AddCallHandler(
         typeof(ExceptionCallHandler),
         new InjectionConstructor(new ResolvedParameter<ExceptionPolicyImpl>(exceptionPolicyName)));
 }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:13,代码来源:ExceptionCallHandlerFixture.cs


注:本文中的IUnityContainer.Configure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。