本文整理汇总了C#中ConventionBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ConventionBuilder类的具体用法?C# ConventionBuilder怎么用?C# ConventionBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConventionBuilder类属于命名空间,在下文中一共展示了ConventionBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CompleteInitialization
public static void CompleteInitialization()
{
Assembly[] partsAssemblies;
lock (_initLock)
{
if (_isInitialized)
return;
_isInitialized = true;
partsAssemblies = _partAssemblies.Union(FindWebApplicationAssemblies()).ToArray();
}
var conventions = new ConventionBuilder()
.WithMvcConventions()
.WithEagerConstructionSupport();
conventions.ForTypesUnderNamespace("Parts").Export().ExportInterfaces();
var container = new ContainerConfiguration()
.WithDefaultConventions(conventions)
.WithAssemblies(partsAssemblies)
.WithApplicationSettings()
.CreateContainer();
MvcCompositionProvider.Initialize(container);
CompositionFilterProvider.Install(FilterProviders.Providers);
ImportCapableFilterAttributeFilterProvider.Install(FilterProviders.Providers);
container.ConstructEagerParts();
}
开发者ID:blinds52,项目名称:alt-composition,代码行数:32,代码来源:CompositionProvider.cs
示例2: RegistrationByConvention
public static void RegistrationByConvention(this Container container,
BehaviorConfiguration configuration,
Action<IConventionBuilderSyntax<Lifestyle, Container>> convention)
{
if (configuration == null)
{
configuration = BehaviorConfiguration.Default;
}
var logger = new DiagnosticLogger(configuration);
var serviceMappingTracker = new ServiceMappingTracker(logger);
var implementationFilter = new ImplementationFilter();
var adapter = new SimpleInjectorContainerAdapter(container, serviceMappingTracker, implementationFilter);
var configServiceFilter = ((IBehaviorConfiguration)configuration).GetServiceFilter();
var asmSelector = new AssemblySelector();
var serviceExtractor = new ServiceExtractor();
var containerDecorator = new ContainerLogger<Lifestyle>(adapter, logger);
var serviceFilterAggregator = new ServiceFilterAggregator(new IServiceFilter[] { configServiceFilter, implementationFilter, serviceExtractor, serviceMappingTracker });
using (var builder = new ConventionBuilder<Lifestyle>(containerDecorator,
asmSelector,
serviceFilterAggregator,
serviceExtractor))
{
var importer = new ConventionBuilderSyntaxDecorator<Lifestyle, Container>(builder, container, implementationFilter, asmSelector);
convention(importer);
}
}
开发者ID:pcsikos,项目名称:ConventionalRegistration,代码行数:28,代码来源:ContainerExtensions.cs
示例3: 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
示例4: UsingNLog
public void UsingNLog()
{
var writer = GetTrace();
LoggingConfiguration config = new LoggingConfiguration();
TraceTarget target = new TraceTarget();
target.Layout = "NLOG [${level:uppercase=true}] ${message}";
config.AddTarget("trace", target);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, target));
LogManager.Configuration = config;
ConventionBuilder.Logger = t => LogManager.GetLogger(t);
var builder = new ConventionBuilder();
builder.ScanThisAssembly().For<HandlerConventions>();
var convention = builder.Build();
Approvals.VerifyAll(writer
.ToString()
.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.OrderBy(s => s), "");
}
开发者ID:distantcam,项目名称:conventional,代码行数:25,代码来源:LoggingTests.cs
示例5: 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
示例6: AddWinRTSpecificConventions
static partial void AddWinRTSpecificConventions( ConventionBuilder builder )
{
var assembly = new PublicKeyTokenSpecification( typeof( Host ) );
var settingsFlyout = new SettingsFlyoutSpecification();
builder.ForTypesMatching( settingsFlyout.IsSatisfiedBy ).Export().Export<SettingsFlyout>().ExportInterfaces( assembly.IsSatisfiedBy ).ImportProperties( p => p != null && p.Name == "Model" );
}
开发者ID:WaffleSquirrel,项目名称:More,代码行数:7,代码来源:Host.cs
示例7: StandardExportInterfacesShouldWork
public void StandardExportInterfacesShouldWork()
{
// Export all interfaces except IDisposable, Export contracts on types without interfaces. except for disposable types
var builder = new ConventionBuilder();
builder.ForTypesMatching((t) => true).ExportInterfaces();
builder.ForTypesMatching((t) => t.GetTypeInfo().ImplementedInterfaces.Where((iface) => iface != typeof(System.IDisposable)).Count() == 0).Export();
var container = new ContainerConfiguration()
.WithPart<Standard>(builder)
.WithPart<Dippy>(builder)
.WithPart<Derived>(builder)
.WithPart<BareClass>(builder)
.CreateContainer();
var importer = new Importer();
container.SatisfyImports(importer);
Assert.NotNull(importer.First);
Assert.True(importer.First.Count() == 3);
Assert.NotNull(importer.Second);
Assert.True(importer.Second.Count() == 3);
Assert.NotNull(importer.Third);
Assert.True(importer.Third.Count() == 3);
Assert.NotNull(importer.Fourth);
Assert.True(importer.Fourth.Count() == 3);
Assert.NotNull(importer.Fifth);
Assert.True(importer.Fifth.Count() == 3);
Assert.Null(importer.Base);
Assert.Null(importer.Derived);
Assert.Null(importer.Dippy);
Assert.Null(importer.Standard);
Assert.Null(importer.Disposable);
Assert.NotNull(importer.BareClass);
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:35,代码来源:PartBuilderInterfaceTests.cs
示例8: 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
示例9: 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
示例10: CreateContainer
protected static CompositionContext CreateContainer(ConventionBuilder rb, params Type[] types)
{
return new ContainerConfiguration()
.WithParts(types)
.WithDefaultConventions(rb)
.CreateContainer();
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:7,代码来源:ContainerTests.cs
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: AddPlatformSpecificConventions
static partial void AddPlatformSpecificConventions( ConventionBuilder builder )
{
var assembly = new PublicKeyTokenSpecification( typeof( Host ) );
var window = new AssignableSpecification<Window>().And( new AssignableSpecification<IShellView>().Not() );
var userControl = new AssignableSpecification<UserControl>().And( new AssignableSpecification<IShellView>().Not() );
builder.ForTypesMatching( window.IsSatisfiedBy ).Export().ExportInterfaces( assembly.IsSatisfiedBy ).ImportProperties( p => p != null && p.Name == "Model" );
builder.ForTypesMatching( userControl.IsSatisfiedBy ).Export().ExportInterfaces( assembly.IsSatisfiedBy ).ImportProperties( p => p != null && p.Name == "Model" );
}
开发者ID:WaffleSquirrel,项目名称:More,代码行数:9,代码来源:Host.cs
注:本文中的ConventionBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论