コード例 #1
0
        static void Main(string[] args)
        {
            InterceptionConfiguration cfg = new InterceptionConfiguration()
                                            .AddInterceptor(new DynamicProxyInterceptor(new LoggingInterceptor()));

            //GenericTypeCatalog typeCatalog = new GenericTypeCatalog(typeof(GenericClass<int>), typeof(IGenericInterface<>));
            //AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            //AggregateCatalog aggregateCatalog = new AggregateCatalog(assemblyCatalog, typeCatalog);
            //GenericCatalog genericCatalog = new GenericCatalog(aggregateCatalog);
            //InterceptingCatalog interceptingCatalog = new InterceptingCatalog(genericCatalog, cfg);
            //CompositionContainer container = new CompositionContainer(interceptingCatalog);

//            GenericContractTypeMapping mapping = new GenericContractTypeMapping(typeof(IGenericInterface<>), typeof(GenericClass<>));

            TypeCatalog      typeCatalog      = new TypeCatalog(typeof(SampleClass), typeof(OrderProcessor), typeof(CtorOrderProcessor));
            AssemblyCatalog  assemblyCatalog  = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            GenericCatalog   genericCatalog   = new GenericCatalog(new TestGenericContractRegistry());
            AggregateCatalog aggregateCatalog = new AggregateCatalog(typeCatalog, genericCatalog);
            //CompositionContainer container = new CompositionContainer(aggregateCatalog);

            CompositionContainer container = new CompositionContainer(aggregateCatalog);
            var orderProcessor             = container.GetExportedValue <OrderProcessor>();
            var generic = container.GetExportedValue <IGenericInterface <string> >();

            CatalogExportProvider provider = new CatalogExportProvider(aggregateCatalog);

            provider.SourceProvider = provider;

            var instance = provider.GetExportedValue <ISampleInterface>();//container.GetExportedValue<ISampleInterface>();

            instance.Method1("test", 5);

            var genericInstance = provider.GetExportedValue <OrderProcessor>();//container.GetExportedValue<IGenericInterface<int>>();
            //var orderProcessor = provider.GetExportedValue<CtorOrderProcessor>();
        }
コード例 #2
0
        public void CreationPolicyShared_MultipleCallsReturnSameInstance()
        {
            var catalog  = CatalogFactory.CreateAttributed(typeof(CreationPolicyShared));
            var provider = new CatalogExportProvider(catalog);

            provider.SourceProvider = ContainerFactory.Create();

            var export = provider.GetExportedValue <CreationPolicyShared>();

            for (int i = 0; i < 5; i++) // 5 is arbitrarily chosen
            {
                var export1 = provider.GetExportedValue <CreationPolicyShared>();

                Assert.Equal(export, export1);
            }
        }
コード例 #3
0
        public void CreationPolicyNonShared_MultipleCallsReturnsDifferentInstances()
        {
            var catalog  = CatalogFactory.CreateAttributed(typeof(CreationPolicyNonShared));
            var provider = new CatalogExportProvider(catalog);

            provider.SourceProvider = ContainerFactory.Create();

            List <CreationPolicyNonShared> list = new List <CreationPolicyNonShared>();
            var export = provider.GetExportedValue <CreationPolicyNonShared>();

            list.Add(export);

            for (int i = 0; i < 5; i++) // 5 is arbitrarily chosen
            {
                export = provider.GetExportedValue <CreationPolicyNonShared>();

                CollectionAssert.DoesNotContain(list, export);
                list.Add(export);
            }
        }