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