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


C# ConventionBuilder.ForTypesDerivedFrom方法代码示例

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


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

示例1: RegisterConventions

        /// <summary>
        /// Registers the conventions.
        /// </summary>
        /// <param name="builder">The registration builder.</param>
        public void RegisterConventions(ConventionBuilder builder)
        {
            builder
                .ForTypesDerivedFrom<IGameManager>()
                .Export(b => b.AsContractType<IGameManager>())
                .Shared(ScopeNames.User);

            builder
                .ForTypesDerivedFrom<IUser>()
                .Export(b => b.AsContractType<IUser>())
                .Shared(ScopeNames.User);
        }
开发者ID:raimu,项目名称:kephas,代码行数:16,代码来源:GameConventionRegistrar.cs

示例2: DefineConventions

        private static AttributedModelProvider DefineConventions()
        {
            var rb = new ConventionBuilder();

            rb.ForTypesDerivedFrom<IController>().Export();

            rb.ForTypesDerivedFrom<IHttpController>().Export();

            rb.ForTypesMatching(IsAPart)
                .Export()
                .ExportInterfaces();

            return rb;
        }
开发者ID:SpectralAngel,项目名称:Antem,代码行数:14,代码来源:MvcContainerConfiguration.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: MapType_OverridingSelectionOfConventionSelectedConstructor

        public void MapType_OverridingSelectionOfConventionSelectedConstructor()
        {
            var builder = new ConventionBuilder();

            builder.
                ForTypesDerivedFrom<IFoo>().
                Export<IFoo>();

            builder.ForType<FooImplWithConstructors>()
                .SelectConstructor(cis => cis.ElementAtOrDefault(1));

            var fooImplWithConstructors = typeof(FooImplWithConstructors).GetTypeInfo();

            var constructor1 = fooImplWithConstructors.DeclaredConstructors.Where(c => c.GetParameters().Length == 0).Single();
            var constructor2 = fooImplWithConstructors.DeclaredConstructors.Where(c => c.GetParameters().Length == 1).Single();
            var constructor3 = fooImplWithConstructors.DeclaredConstructors.Where(c => c.GetParameters().Length == 2).Single();


            // necessary as BuildConventionConstructorAttributes is only called for type level query for attributes
            Assert.Equal(0, builder.GetCustomAttributes(typeof(FooImplWithConstructors), constructor1).Count());
            Assert.Equal(0, builder.GetCustomAttributes(typeof(FooImplWithConstructors), constructor3).Count());

            var ci = constructor2;
            var attrs = builder.GetCustomAttributes(typeof(FooImplWithConstructors), ci);
            Assert.Equal(1, attrs.Count());
            Assert.Equal(typeof(ImportingConstructorAttribute), attrs.FirstOrDefault().GetType());
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:27,代码来源:ConventionBuilderTests.cs

示例5: 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

示例6: AsContractName_AndContractType_SetsContractNameAndType

        public void AsContractName_AndContractType_SetsContractNameAndType()
        {
            var builder = new ConventionBuilder();
            builder.ForTypesDerivedFrom<IFoo>().Export((e) => e.AsContractName("hey").AsContractType(typeof(IFoo)));

            ExportAttribute exportAtt = GetExportAttribute(builder);
            Assert.Equal("hey", exportAtt.ContractName);
            Assert.Equal(typeof(IFoo), exportAtt.ContractType);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:ExportBuilderTests.cs

示例7: AsContractTypeOfT_SetsContractType

        public void AsContractTypeOfT_SetsContractType()
        {
            var builder = new ConventionBuilder();
            builder.ForTypesDerivedFrom<IFoo>().Export((e) => e.AsContractType<IFoo>());

            ExportAttribute exportAtt = GetExportAttribute(builder);
            Assert.Equal(typeof(IFoo), exportAtt.ContractType);
            Assert.Null(exportAtt.ContractName);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:ExportBuilderTests.cs

示例8: RegisterExports

        private static AttributedModelProvider RegisterExports()
        {
            var builder = new ConventionBuilder();
            //builder.ForType<learner>().Export<learner>();
            //builder.ForTypesMatching
            //    (x => x.GetProperty("SourceMaterial") != null).Export<exam>();

            builder.ForTypesDerivedFrom<IJob>().Export<IJob>();

            return builder;
        }
开发者ID:supuy-ruby,项目名称:GitCandy,代码行数:11,代码来源:MefConfig.cs

示例9: GetConventions

        private static ConventionBuilder GetConventions()
        {
            var conventions = new ConventionBuilder();

            conventions.ForTypesDerivedFrom<IFormattingFilter>()
                .Export<IFormattingFilter>();

            conventions.ForTypesDerivedFrom<ISyntaxFormattingRule>()
                .Export<ISyntaxFormattingRule>();
            conventions.ForTypesDerivedFrom<ILocalSemanticFormattingRule>()
                .Export<ILocalSemanticFormattingRule>();
            conventions.ForTypesDerivedFrom<IGlobalSemanticFormattingRule>()
                .Export<IGlobalSemanticFormattingRule>();

            conventions.ForType<Options>()
                .Export();

            conventions.ForTypesDerivedFrom<IFormattingEngine>()
                .Export<IFormattingEngine>();

            return conventions;
        }
开发者ID:michaelcfanning,项目名称:codeformatter,代码行数:22,代码来源:FormattingEngine.cs

示例10: Bootstrap

        public void Bootstrap()
        {
            var conventions = new ConventionBuilder();
            conventions.ForTypesDerivedFrom<ICalculator>().Export<ICalculator>().Shared();
            conventions.ForType<Program>().ImportProperty<ICalculator>(p => p.Calculator);

            var configuration = new ContainerConfiguration()
                .WithDefaultConventions(conventions)
                .WithAssemblies(GetAssemblies("c:/addins"));

            using (CompositionHost host = configuration.CreateContainer())
            {
                host.SatisfyImports(this, conventions);
            }
        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:15,代码来源:Program.cs

示例11: MapType_ShouldReturnProjectedAttributesForType

        public void MapType_ShouldReturnProjectedAttributesForType()
        {
            var builder = new ConventionBuilder();

            builder.
                ForTypesDerivedFrom<IFoo>().
                Export<IFoo>();

            var fooImplAttributes = builder.GetDeclaredAttributes(typeof(FooImpl), typeof(FooImpl).GetTypeInfo());
            var fooImplWithConstructorsAttributes = builder.GetDeclaredAttributes(typeof(FooImplWithConstructors), typeof(FooImplWithConstructors).GetTypeInfo());

            var exports = new List<object>();

            exports.AddRange(fooImplAttributes);
            exports.AddRange(fooImplWithConstructorsAttributes);
            Assert.Equal(2, exports.Count);

            foreach (var exportAttribute in exports)
            {
                Assert.Equal(typeof(IFoo), ((ExportAttribute)exportAttribute).ContractType);
                Assert.Null(((ExportAttribute)exportAttribute).ContractName);
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:23,代码来源:ConventionBuilderTests.cs

示例12: ConfigureMef

        private static void ConfigureMef()
        {
            var conventions = new ConventionBuilder();

            conventions.ForTypesDerivedFrom<ViewModelBase>()
                       .Export();

            conventions.ForTypesMatching(x => x.Name.EndsWith("Service"))
                       .ExportInterfaces();

            ViewLocator.BuildMefConventions(conventions);

            var configuration = new ContainerConfiguration()
                .WithAssembly(typeof(App).GetTypeInfo().Assembly, conventions)
                .WithAssembly(typeof(LinquaLib).GetTypeInfo().Assembly, conventions)
                .WithAssembly(typeof(FrameworkUwp).GetTypeInfo().Assembly)
                .WithProvider(new DefaultExportDescriptorProvider());

            var container = configuration.CreateContainer();

            CompositionManager.Initialize(container);

            App.CompositionManager = CompositionManager.Current;
        }
开发者ID:pglazkov,项目名称:Linqua,代码行数:24,代码来源:Bootstrapper.cs

示例13: CreateWithDefaultConventions

        public static IDependencyResolver CreateWithDefaultConventions(Assembly[] appAssemblies)
        {
            var conventions = new ConventionBuilder();

            conventions.ForTypesDerivedFrom<IHttpController>()
                .Export();

            conventions.ForTypesMatching(t => t.Namespace != null && t.Namespace.EndsWith(".Parts"))
                .Export()
                .ExportInterfaces();

            var container = new ContainerConfiguration()
                .WithAssemblies(appAssemblies, conventions)
                .CreateContainer();

            return new MefDependencyResolver(container);
        }
开发者ID:ChrisMissal,项目名称:WebApiContrib.IoC.Mef,代码行数:17,代码来源:MefDependencyResolver.cs

示例14: AsContractName_AndContractType_ComputeContractNameFromType

        public void AsContractName_AndContractType_ComputeContractNameFromType()
        {
            var builder = new ConventionBuilder();
            builder.ForTypesDerivedFrom<IFoo>().Export(e => e.AsContractName(t => "Contract:" + t.FullName).AsContractType<IFoo>());

            ExportAttribute exportAtt = GetExportAttribute(builder);
            Assert.Equal("Contract:" + typeof(FooImpl).FullName, exportAtt.ContractName);
            Assert.Equal(typeof(IFoo), exportAtt.ContractType);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:ExportBuilderTests.cs

示例15: AddMetadataFuncVal_AddsExportMetadataAttribute

        public void AddMetadataFuncVal_AddsExportMetadataAttribute()
        {
            var builder = new ConventionBuilder();
            builder.ForTypesDerivedFrom<IFoo>().Export(e => e.AddMetadata("name", t => t.Name));

            ExportMetadataAttribute exportAtt = GetExportMetadataAttribute(builder);
            Assert.Equal("name", exportAtt.Name);
            Assert.Equal(typeof(FooImpl).Name, exportAtt.Value);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:ExportBuilderTests.cs


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