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


C# UnityContainer.ResolveAll方法代码示例

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


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

示例1: ResolveAllOnlyReturnsInterfaceRegistrations

        public void ResolveAllOnlyReturnsInterfaceRegistrations()
        {
            ITest iTest;

            ATest objA = new ATest();
            BTest objB = new BTest();
            CTest objC = new CTest();

            objA.Strtest = "Hi";

            UnityContainer uc1 = new UnityContainer();

            uc1.RegisterType<ITest, ATest>();

            iTest = objA;
            uc1.RegisterInstance("ATest", iTest);
            iTest = objB;
            uc1.RegisterInstance("BTest", iTest);
            iTest = objC;
            uc1.RegisterInstance("CTest", iTest);

            List<ATest> list = new List<ATest>(uc1.ResolveAll<ATest>());
            List<ITest> list3 = new List<ITest>(uc1.ResolveAll<ITest>());

            Assert.AreEqual(0, list.Count);
            Assert.AreEqual(3, list3.Count);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:27,代码来源:ContainerBasicFixture.cs

示例2: Can_add_all_as_singletons

        public void Can_add_all_as_singletons()
        {
            var container = new UnityContainer();

            container.Configure(x => x.Scan(scan =>
            {
                scan.AssemblyContaining<FooRegistry>();
                scan.WithAddAllConvention().TypesImplementing<IHaveManyImplementations>().AsSingleton();
            }));

            Assert.That(container.ResolveAll<IHaveManyImplementations>().First(), Is.SameAs(container.ResolveAll<IHaveManyImplementations>().First()));
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:12,代码来源:AddAllConventionTests.cs

示例3: Adds_all_types_implementing_the_specified_type_with_default_name

        public void Adds_all_types_implementing_the_specified_type_with_default_name()
        {
            var container = new UnityContainer();

            container.Configure(x => x.Scan(scan =>
            {
                scan.AssemblyContaining<FooRegistry>();
                scan.WithAddAllConvention().TypesImplementing<IHaveManyImplementations>();
            }));

            Assert.That(container.ResolveAll<IHaveManyImplementations>().Count(), Is.EqualTo(2));
            Assert.That(container.ResolveAll<IHaveManyImplementations>().First(), Is.Not.SameAs(container.ResolveAll<IHaveManyImplementations>().First()));
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:13,代码来源:AddAllConventionTests.cs

示例4: RegisterSameType

        public void RegisterSameType()
        {
            IUnityContainer uc = new UnityContainer()
                .RegisterType<ITemporary, Temp>("First");

            List<ITemporary> temporaries = new List<ITemporary>(uc.ResolveAll<ITemporary>());

            Assert.AreEqual(1, temporaries.Count);

            uc.RegisterType<ITemporary, Temp2>("First");
            temporaries = new List<ITemporary>(uc.ResolveAll<ITemporary>());

            Assert.AreEqual(1, temporaries.Count);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:14,代码来源:ContainerRegisterFixture.cs

示例5: Main

        static void Main(string[] args)
        {
            IUnityContainer container = new UnityContainer();

            // only do this if CSLA DataPortal is NOT deployed on a physical server
            // if this Appsetting has value, it means that DataPortal is on a separate physical server
            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["CslaDataPortalProxy"]))
            {
                // register all the composers you need to properly register dependencies that are used in your business objects
                // add a name to properly distinguish each belonging to type IContainerComposer
                // so that ResolveAll<IContainerComposer>() will actually return a value
                container.RegisterType(typeof(IContainerComposer), typeof(DataContextComposer), typeof(DataContextComposer).ToString());
                container.RegisterType(typeof(IContainerComposer), typeof(JustAnotherSampleServiceComposer), typeof(JustAnotherSampleServiceComposer).ToString());

                ApplicationContext.DataPortalActivator = new CustomDataPortalActivator(container.ResolveAll<IContainerComposer>());
                CS.DataPortal.InterceptorType = typeof(CustomDataPortalInterceptor);
            }

            // call your bootstrapper for your UI dependencies
            bootstrapUIDependencies(container);


            MyExecutionClass runner = container.Resolve<MyExecutionClass>();
            runner.Run();
        }
开发者ID:aiampogi,项目名称:csla.net-with-dependency-injection-sample,代码行数:25,代码来源:Program.cs

示例6: UnityWithConfiguration

        private void UnityWithConfiguration()
        {
            // Create and populate a new Unity container from configuration            
            UnityConfigurationSection UnityConfigurationSectionObject = (UnityConfigurationSection)ConfigurationManager.GetSection("UnityBlockConfiguration");
            IUnityContainer UnityContainerObject = new UnityContainer();

            UnityConfigurationSectionObject.Containers["ContainerOne"].Configure(UnityContainerObject);
            Console.WriteLine("\nRetrieved the populated Unity Container.");

            // Get the logger to write a message and display the result. No name in config file.
            ILogger ILoggerInstance = UnityContainerObject.Resolve < ILogger>();            
            Console.WriteLine("\n" + ILoggerInstance.WriteMessage("HELLO Default UNITY!"));

            // Resolve an instance of the appropriate class registered for ILogger 
            // Using the specified mapping name in the configuration file (may be empty for the default mapping)
            ILoggerInstance = UnityContainerObject.Resolve<ILogger>("StandardLoggerMappedInConfig");
            
            // Get the logger to write a message and display the result
            Console.WriteLine("\n" + ILoggerInstance.WriteMessage("HELLO StandardLogger!"));
            
            // Resolve an instance of the appropriate class registered for ILogger 
            // Using the specified mapping name (may be empty for the default mapping)
            ILoggerInstance = UnityContainerObject.Resolve<ILogger>("SuperFastLoggerMappedInConfig");
            
            // Get the logger to write a message and display the result
            Console.WriteLine("\n" + ILoggerInstance.WriteMessage("HELLO SuperFastLogger!"));

            // Constructor Injection.
            // Resolve an instance of the concrete MyObjectWithInjectedLogger class 
            // This class contains a reference to ILogger in the constructor parameters 
            MyObjectWithInjectedLogger MyObjectWithInjectedLoggerInstance = UnityContainerObject.Resolve<MyObjectWithInjectedLogger>();
            // Get the injected logger to write a message and display the result
            Console.WriteLine("\n" + MyObjectWithInjectedLoggerInstance.GetObjectStringResult());

            // Throws error as we are trying to create instance for interface.
            //IMyInterface IMyInterfaceObject = UnityContainerObject.Resolve<IMyInterface>();

            IMyInterface IMyInterfaceObject = UnityContainerObject.Resolve<IMyInterface>();
            Console.WriteLine("\n" + IMyInterfaceObject.GetObjectStringResult());

            //If we are not sure whether a named registration exists for an object, 
            // we can use the ResolveAll method to obtain a list of registrations and mappings, and then check for the object we need in the list returned by this method. 
            // However, this will cause the container to generate all the objects for all named registrations for the specified object type, which will affect performance.
            IEnumerable<object> IEnumerableObjects = UnityContainerObject.ResolveAll(typeof(ILogger));
            int i = 0;
            foreach (ILogger foundObject in IEnumerableObjects)
            {
                // Convert the object reference to the "real" type
                ILogger theObject = foundObject as ILogger;
                i++;
                if (null != theObject)
                {
                    Console.WriteLine(theObject.WriteMessage("Reading Object " + i.ToString()));
                }
            }
            
            UnityContainerObject.Teardown(IMyInterfaceObject);

            Console.ReadLine();
        }
开发者ID:mac10688,项目名称:PublicWorkspace,代码行数:60,代码来源:Program.cs

示例7: CreateUnityContainer

        public static IUnityContainer CreateUnityContainer()
        {
            var container = new UnityContainer();
            container.RegisterType<IMediator, Mediator>();
            var types = AllClasses.FromAssemblies( typeof( Program ).Assembly );

            container.RegisterTypes(
                types,
                WithMappings.FromAllInterfaces,
                GetName,
                GetLifetimeManager,
                null,
                true );

            container.RegisterInstance<SingleInstanceFactory>( t =>
             {
                 var pipeline = container.Resolve(
                     typeof( MediatorPipeline<,> ).MakeGenericType( t.GetGenericArguments() )
                 );

                 return pipeline;

             } );
            container.RegisterInstance<MultiInstanceFactory>( t => container.ResolveAll( t ) );

            return container;
        }
开发者ID:mickeyr,项目名称:UnityMediatrPipelineTest,代码行数:27,代码来源:Program.cs

示例8: FixtureSetup

        public void FixtureSetup()
        {
            this.unityContainer = new UnityContainer();
            IoC.Initialize(
                (x, y) => this.unityContainer.RegisterType(x, y),
                (x, y) => this.unityContainer.RegisterInstance(x, y),
                (x) => { return unityContainer.Resolve(x); },
                (x) => { return unityContainer.ResolveAll(x); });

            // Context Factory
            RavenUnitOfWorkFactory ctxFactory = new RavenUnitOfWorkFactory();
            Raven.Client.Document.DocumentStore sessionFactory = ctxFactory.CreateDocumentStore();

            IoC.RegisterInstance<IDatabaseManager>(ctxFactory);
            IoC.RegisterInstance<IUnitOfWorkFactory>(ctxFactory);

            this.unityContainer.RegisterType<IDocumentSession, IDocumentSession>(new InjectionFactory((c) =>
            {
                return ctxFactory.CurrentDocumentSession;
            }));

            // Repositories
            this.unityContainer.RegisterType<IEntityARepository, EntityARavenRepository>();

            // Services
            if (!ctxFactory.DatabaseExists())
            {
                ctxFactory.CreateDatabase();
            }

            ctxFactory.ValidateDatabaseSchema();
        }
开发者ID:ufozy,项目名称:Account.Hexa.Core,代码行数:32,代码来源:RavenTests.cs

示例9: RegisterTypeWithoutNameandGetAll

        public void RegisterTypeWithoutNameandGetAll()
        {
            IUnityContainer uc = new UnityContainer().RegisterType<ITemporary, Temp>().RegisterType<ITemporary, Temporary>();

            List<ITemporary> temporaries = new List<ITemporary>(uc.ResolveAll<ITemporary>());

            Assert.AreEqual(0, temporaries.Count);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:8,代码来源:ContainerRegisterFixture.cs

示例10: ConfigureContainerbyAddingExteralPolicy

 public void ConfigureContainerbyAddingExteralPolicy()
 {
     IUnityContainer container = new UnityContainer();
     container.AddNewExtension<Interception>();
     container.Configure<Interception>().AddPolicy("myRDP");
     List<InjectionPolicy> policy = new List<InjectionPolicy>(container.ResolveAll<InjectionPolicy>());
     Assert.AreEqual("myRDP", policy[1].Name);
 }
开发者ID:CFMITL,项目名称:unity,代码行数:8,代码来源:ConvenienceInterceptionAPI.cs

示例11: ResolvingAllRegistratiosnForaTypeReturnsAnEmptyArrayWhenNothingIsRegisterd

        public void ResolvingAllRegistratiosnForaTypeReturnsAnEmptyArrayWhenNothingIsRegisterd()
        {
            IUnityContainer container = new UnityContainer();

            IEnumerable<CollectionSupportTestClass> resolved = container.ResolveAll<CollectionSupportTestClass>();
            List<CollectionSupportTestClass> resolvedList = new List<CollectionSupportTestClass>(resolved);

            Assert.AreEqual(0, resolvedList.Count);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:9,代码来源:CollectionSupportFixture.cs

示例12: ConfigureContainerbyAddingEmptyHandlerRuleThrowException

 public void ConfigureContainerbyAddingEmptyHandlerRuleThrowException()
 {
     IUnityContainer container = new UnityContainer();
     container.AddNewExtension<Interception>();
     container.Configure<Interception>().
         AddPolicy("myRDP").
         AddCallHandler(String.Empty).
         AddMatchingRule(String.Empty);
     List<InjectionPolicy> policy = new List<InjectionPolicy>(container.ResolveAll<InjectionPolicy>());
 }
开发者ID:CFMITL,项目名称:unity,代码行数:10,代码来源:ConvenienceInterceptionAPI.cs

示例13: BuildUnityContainer

        private static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();

            container.RegisterType<IMovieDataAccess, YoutubeService>("YoutubeService");
            container.RegisterType<IMovieDataAccess, OMDBService>("OMDBService");
            container.RegisterInstance<IAppCache>(MovieTrailers.DataAccess.AppCache.Instance);
            container.RegisterInstance<IMovieTrailerService>(new MovieTrailerService(container.ResolveAll<IMovieDataAccess>()));
            return container;
        }
开发者ID:sviridovserg,项目名称:movietrailers,代码行数:10,代码来源:Bootstrapper.cs

示例14: RegisterMultipleImplementationsOfTheSameType

        public void RegisterMultipleImplementationsOfTheSameType()
        {
            var container = new UnityContainer();
            container.RegisterType<IIngredient, Steak>("meat");
            container.RegisterType<IIngredient, SauceBéarnaise>("sauce");

            var ingredients = container.ResolveAll<IIngredient>();

            Assert.True(ingredients.OfType<Steak>().Any());
            Assert.True(ingredients.OfType<SauceBéarnaise>().Any());
        }
开发者ID:mesta1,项目名称:dli.net_sourcecode,代码行数:11,代码来源:MenuFacts.cs

示例15: Can_add_all_implementations_of_an_open_generic

        public void Can_add_all_implementations_of_an_open_generic()
        {
            var container = new UnityContainer();

            container.Configure(x => x.Scan(scan =>
            {
                scan.AssemblyContaining<FooRegistry>();
                scan.WithAddAllConvention().TypesImplementing(typeof(IHandler<>));
            }));

            Assert.That(container.ResolveAll<IHandler<Message>>().Count(), Is.EqualTo(2));
        }
开发者ID:jdineshk,项目名称:UnityConfiguration,代码行数:12,代码来源:AddAllConventionTests.cs


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