本文整理汇总了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);
}
示例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;
}
示例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();
}
示例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());
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}