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


C# ConventionBuilder.ForType方法代码示例

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


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

示例1: GetContainerConfiguration

        // *** Protected Methods ***

        protected virtual ContainerConfiguration GetContainerConfiguration()
        {
            // Create a basic container configuration with,
            //    - The application's main assembly (i.e. that defines the current Application subclass)
            //    - The Cocoon assembly (via the INavigationManager interface)
            //    - The Cocoon.MEF assembly (via the CocoonBootstrapper class)

            ConventionBuilder cocoonConventionBuilder = new ConventionBuilder();

            cocoonConventionBuilder.ForType<NavigationManager>().Export<INavigationManager>()
                                                                .Shared()
                                                                .SelectConstructor(ctors => ctors.First(), (info, builder) =>
                                                                    {
                                                                        if (info.ParameterType == typeof(INavigationTarget))
                                                                            builder.AllowDefault();
                                                                    });

            cocoonConventionBuilder.ForType<ActivationManager>().Export<IActivationManager>().Shared();
            cocoonConventionBuilder.ForType<LifetimeManager>().Export<ILifetimeManager>().Shared();
            cocoonConventionBuilder.ForType<StorageManager>().Export<IStorageManager>().Shared();

            return new ContainerConfiguration()
                        .WithAssembly(Application.Current.GetType().GetTypeInfo().Assembly)
                        .WithAssembly(typeof(INavigationManager).GetTypeInfo().Assembly, cocoonConventionBuilder)
                        .WithAssembly(typeof(CocoonBootstrapper).GetTypeInfo().Assembly);
        }
开发者ID:shiftkey,项目名称:envelop,代码行数:28,代码来源:CocoonBootstrapper.cs

示例2: GetOkraContainerConfiguration

        // *** Protected Methods ***

        protected ContainerConfiguration GetOkraContainerConfiguration()
        {
            // Create a basic container configuration with,
            //    - The Okra assembly (via the INavigationManager interface)
            //    - The Okra.MEF assembly (via the OkraBootstrapper class)

            ConventionBuilder okraConventionBuilder = new ConventionBuilder();

            okraConventionBuilder.ForType<NavigationManager>().Export<INavigationManager>()
                                                                .Shared()
                                                                .SelectConstructor(ctors => ctors.First(), (info, builder) =>
                                                                {
                                                                    if (info.ParameterType == typeof(INavigationTarget))
                                                                        builder.AllowDefault();
                                                                });

            okraConventionBuilder.ForType<SettingsPaneManager>().Export<ISettingsPaneManager>().Shared();
            okraConventionBuilder.ForType<ActivationManager>().Export<IActivationManager>().Shared();
            okraConventionBuilder.ForType<SearchManager>().Export<ISearchManager>().Shared();
            okraConventionBuilder.ForType<ShareSourceManager>().Export<IShareSourceManager>().Shared();
            okraConventionBuilder.ForType<ShareTargetManager>().Export<IShareTargetManager>().Shared();
            okraConventionBuilder.ForType<LifetimeManager>().Export<ILifetimeManager>().Shared();
            okraConventionBuilder.ForType<StorageManager>().Export<IStorageManager>().Shared();
            okraConventionBuilder.ForType<LaunchActivationHandler>().Export<ILaunchActivationHandler>().Shared();

            return new ContainerConfiguration()
                        .WithAssembly(typeof(INavigationManager).GetTypeInfo().Assembly, okraConventionBuilder)
                        .WithAssembly(typeof(OkraBootstrapper).GetTypeInfo().Assembly);
        }
开发者ID:Valks,项目名称:Okra,代码行数:31,代码来源:OkraBootstrapper.cs

示例3: ConfigureContainer

        public static void ConfigureContainer()
        {
            var containerConventions = new ConventionBuilder();

            containerConventions.ForType<DbProductRepository>()
                .ExportInterfaces()
                .SelectConstructorWithMostParameters()
                .InstancePerHttpRequest();

            containerConventions.ForType<DbLogger>()
                .ExportInterfaces()
                .SelectConstructorWithMostParameters()
                .InstancePerHttpRequest();

            containerConventions.ForType<ProductDbContext>()
                .Export()
                .InstancePerHttpRequest();

            containerConventions.ForTypesDerivedFrom<Controller>()
                .Export<IController>()
                .Export()
                .SelectConstructorWithMostParameters();

            var containerConfig = new ContainerConfiguration();
            containerConfig.WithAssembly(Assembly.GetExecutingAssembly(), containerConventions);

            containerConfig.CreateContainer().UseWithMvc();
        }
开发者ID:Hem,项目名称:MvcMefProvider,代码行数:28,代码来源:MefContainer.cs

示例4: AsContractName_AndContractType_ComputeContractNameFromType

        public void AsContractName_AndContractType_ComputeContractNameFromType()
        {
            var builder = new ConventionBuilder();
            builder.ForType<FooImpl>().ImportProperty((p) => p.IFooProperty, c => c.AsContractName(t => "Contract:" + t.FullName));

            ImportAttribute importAtt = GetImportAttribute(builder);
            Assert.Equal("Contract:" + typeof(IFoo).FullName, importAtt.ContractName);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:ImportBuilderTests.cs

示例5: AsContractName_AndContractType_SetsContractNameAndType

        public void AsContractName_AndContractType_SetsContractNameAndType()
        {
            var builder = new ConventionBuilder();
            builder.ForType<FooImpl>().ImportProperty((p) => p.IFooProperty, (c) => c.AsContractName("hey"));

            ImportAttribute importAtt = GetImportAttribute(builder);
            Assert.Equal("hey", importAtt.ContractName);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:ImportBuilderTests.cs

示例6: CanSpecifyExportsWithConventionBuilder

 public void CanSpecifyExportsWithConventionBuilder()
 {
     var rb = new ConventionBuilder();
     rb.ForType<BarePart>().Export();
     var cc = CreateContainer(rb, typeof(BarePart));
     var x = cc.GetExport<BarePart>();
     Assert.NotNull(x);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:LightContainerTests.cs

示例7: AddUISpecificConventions

        static partial void AddUISpecificConventions( ConventionBuilder builder )
        {
            var viewModel = new ViewModelSpecification();

            builder.ForTypesDerivedFrom<IShellView>().Export().Export<IShellView>().Shared();
            builder.ForTypesMatching( viewModel.IsSatisfiedBy ).Export();
            builder.ForType<EventBroker>().Export<IEventBroker>().Shared();
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:8,代码来源:Host.cs

示例8: AddImportConstraint_AddsImportConstraintMetadataAttribute

        public void AddImportConstraint_AddsImportConstraintMetadataAttribute()
        {
            var builder = new ConventionBuilder();
            builder.ForType<FooImpl>().ImportProperty((p) => p.IFooProperty, (c) => c.AddMetadataConstraint("name", "val"));

            ImportMetadataConstraintAttribute importMetadataConstraint = GetImportMetadataConstraintAttribute(builder);
            Assert.Equal("name", importMetadataConstraint.Name);
            Assert.Equal("val", importMetadataConstraint.Value);
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:9,代码来源:ImportBuilderTests.cs

示例9: WhenExportingInterfaces_NoPredicate_OnlyContractInterfacesAreExported

        public void WhenExportingInterfaces_NoPredicate_OnlyContractInterfacesAreExported()
        {
            var builder = new ConventionBuilder();
            builder.ForType<ClassWithLifetimeConcerns>().ExportInterfaces();

            var attributes = GetExportAttributes(builder, typeof(ClassWithLifetimeConcerns));
            var exportedContracts = attributes.Select(e => e.ContractType).ToArray();
            AssertX.Equivalent(s_contractInterfaces, exportedContracts);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:9,代码来源:ExportInterfacesContractExclusionTests.cs

示例10: AllowDefault_SetsAllowDefaultProperty

        public void AllowDefault_SetsAllowDefaultProperty()
        {
            var builder = new ConventionBuilder();
            builder.ForType<FooImpl>().ImportProperty((p) => p.IFooProperty, (c) => c.AllowDefault());

            ImportAttribute importAtt = GetImportAttribute(builder);
            Assert.True(importAtt.AllowDefault);
            Assert.Null(importAtt.ContractName);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:9,代码来源:ImportBuilderTests.cs

示例11: ImportPropertyTargetingBaseClass_ShouldGenerateImportManyForPropertySelected

        public void ImportPropertyTargetingBaseClass_ShouldGenerateImportManyForPropertySelected()
        {
            var builder = new ConventionBuilder();
            builder.ForType<DerClass>().ImportProperty(p => p.P3); // P3 is IEnumerable<int>

            var importManyAttribute = GetAttributeFromMember(builder, typeof(DerClass), "P3") as ImportManyAttribute;
            Assert.NotNull(importManyAttribute);
            Assert.Null(importManyAttribute.ContractName);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:9,代码来源:PartBuilderOfTInheritanceTests.cs

示例12: ExportInterfaceWithTypeOf2

        public void ExportInterfaceWithTypeOf2()
        {
            var builder = new ConventionBuilder();
            builder.ForType(typeof(CFoo)).Export((c) => c.AsContractType(typeof(IFoo)));

            var exports = builder.GetDeclaredAttributes(typeof(CFoo), typeof(CFoo).GetTypeInfo()).Where<Attribute>(e => e is ExportAttribute).Cast<ExportAttribute>();
            Assert.Equal(1, exports.Count());
            Assert.Equal(exports.First().ContractType, typeof(IFoo));
        }
开发者ID:nblumhardt,项目名称:corefx,代码行数:9,代码来源:ExportBuilderUnitTests.cs

示例13: AsMany_And_ContractName_ChangesGeneratedAttributeToImportMany

        public void AsMany_And_ContractName_ChangesGeneratedAttributeToImportMany()
        {
            var builder = new ConventionBuilder();
            builder.ForType<FooImpl>().ImportProperty((p) => p.IFooProperty, (c) => c.AsContractName("hey").AsMany());

            ImportManyAttribute importAtt = GetImportManyAttribute(builder);
            Assert.NotNull(importAtt);
            Assert.Equal("hey", importAtt.ContractName);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:9,代码来源:ImportBuilderTests.cs

示例14: ExportInterfaceWithTypeOf1

        public void ExportInterfaceWithTypeOf1()
        {
            var builder = new ConventionBuilder();
            builder.ForType<FooImpl>().Export<IFoo>();

            var exports = builder.GetCustomAttributes(typeof(FooImpl), typeof(FooImpl).GetTypeInfo()).Where<Attribute>(e => e is ExportAttribute).Cast<ExportAttribute>();
            Assert.Equal(1, exports.Count());
            Assert.Equal(exports.First().ContractType, typeof(IFoo));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:ExportBuilderTests.cs

示例15: WhenExportingInterfaces_PredicateSpecified_OnlyContractInterfacesAreSeenByThePredicate

        public void WhenExportingInterfaces_PredicateSpecified_OnlyContractInterfacesAreSeenByThePredicate()
        {
            var seenInterfaces = new List<Type>();

            var builder = new ConventionBuilder();
            builder.ForType<ClassWithLifetimeConcerns>().ExportInterfaces(i => { seenInterfaces.Add(i); return true; });

            var attributes = GetExportAttributes(builder, typeof(ClassWithLifetimeConcerns));
            AssertX.Equivalent(s_contractInterfaces, seenInterfaces);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:ExportInterfacesContractExclusionTests.cs


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