本文整理汇总了C#中ContainerConfiguration.GetExport方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerConfiguration.GetExport方法的具体用法?C# ContainerConfiguration.GetExport怎么用?C# ContainerConfiguration.GetExport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerConfiguration
的用法示例。
在下文中一共展示了ContainerConfiguration.GetExport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Implementation
public void Implementation()
{
var types = new[] { typeof(Implemented) }.AsApplicationParts();
var container = new ContainerConfiguration().WithParts( types.AsEnumerable() ).WithProvider( SingletonExportDescriptorProvider.Default ).CreateContainer();
Assert.Same( Implemented.Default, container.GetExport<ISingleton>() );
Assert.Same( Implemented.Default, container.GetExport<Implemented>() );
}
示例2: Basic
public void Basic()
{
var types = new[] { typeof(Singleton) }.AsApplicationParts();
var container = new ContainerConfiguration().WithParts( types.AsEnumerable() ).WithProvider( SingletonExportDescriptorProvider.Default ).CreateContainer();
var export = container.GetExport<Singleton>();
Assert.Same( Singleton.Default, export );
}
示例3: ProvidersCanDetectAbsenceOfAContractItSupports
public void ProvidersCanDetectAbsenceOfAContractItSupports()
{
var container = new ContainerConfiguration()
.WithProvider(new DefaultObjectExportDescriptorProvider())
.CreateContainer();
var o = container.GetExport<object>();
Assert.Equal(DefaultObjectExportDescriptorProvider.DefaultObject, o);
}
示例4: ProvidersCanLocateImplementationsOfAContractItSupports
public void ProvidersCanLocateImplementationsOfAContractItSupports()
{
var container = new ContainerConfiguration()
.WithProvider(new DefaultObjectExportDescriptorProvider())
.WithPart<ExportsObject>()
.CreateContainer();
var o = container.GetExport<object>();
Assert.NotEqual(DefaultObjectExportDescriptorProvider.DefaultObject, o);
}
示例5: MetadataViewsCanCarryDefaultValues
public void MetadataViewsCanCarryDefaultValues()
{
var cc = new ContainerConfiguration()
.WithPart<HasNoName>()
.CreateContainer();
var hn = cc.GetExport<Lazy<HasNoName, OptionallyNamed>>();
Assert.Equal("B", hn.Metadata.Name);
}
示例6: AConcreteTypeWithDictionaryConstructorIsAMetadataView
public void AConcreteTypeWithDictionaryConstructorIsAMetadataView()
{
var cc = new ContainerConfiguration()
.WithPart<HasNameA>()
.CreateContainer();
var hn = cc.GetExport<Lazy<HasNameA, DictionaryName>>();
Assert.Equal("A", hn.Metadata.RetrievedName);
}
示例7: AConcreteTypeWithWritablePropertiesIsAMetadataView
public void AConcreteTypeWithWritablePropertiesIsAMetadataView()
{
var cc = new ContainerConfiguration()
.WithPart<HasNameA>()
.CreateContainer();
var hn = cc.GetExport<Lazy<HasNameA, Named>>();
Assert.Equal("A", hn.Metadata.Name);
}
示例8: AConcreteTypeWithUnsupportedConstructorsCannotBeUsedAsAMetadataView
public void AConcreteTypeWithUnsupportedConstructorsCannotBeUsedAsAMetadataView()
{
var cc = new ContainerConfiguration()
.WithPart<HasNameA>()
.CreateContainer();
var x = Assert.Throws<CompositionFailedException>(() => cc.GetExport<Lazy<HasNoName, InvalidConcreteView>>());
Assert.Equal("The type 'InvalidConcreteView' cannot be used as a metadata view. A metadata view must be a concrete class with a parameterless or dictionary constructor.", x.Message);
}
示例9: Application_Start
protected void Application_Start()
{
SetupAutoMapper();
var container = new ContainerConfiguration()
.WithAssembly(typeof(WebApiApplication).Assembly)
.CreateContainer();
var resolver = new StandaloneDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
GlobalConfiguration.Configure(container.GetExport<WebApiConfig>().Register);
}
示例10: GetOperation
public override Action GetOperation()
{
var c = new ContainerConfiguration()
.WithPart(typeof(X))
.CreateContainer();
return () =>
{
c.GetExport<X>();
};
}
示例11: Basic
public void Basic()
{
var parts = this.Adapt().WithNested().Append( typeof(Protected) ).AsApplicationParts();
var builder = ConventionBuilderFactory.Default.Get();
var container = new ContainerConfiguration().WithParts( parts.AsEnumerable(), builder ).WithProvider( ServicesExportDescriptorProvider.Default ).CreateContainer();
new EnableServicesCommand().Execute();
var dependency = container.GetExport<Dependency>();
Assert.NotNull( dependency );
var export = container.GetExport<IPrimary>();
var primary = Assert.IsType<Primary>( export );
Assert.Equal( 2, primary.Selected.GetParameters().Length );
var exported = container.GetExport<Exported>();
Assert.Equal( 3, exported.Selected.GetParameters().Length );
var external = container.GetExport<ExternalDependencyExport>();
Assert.Equal( 3, external.Selected.GetParameters().Length );
Assert.Throws<CompositionFailedException>( () => container.GetExport<Protected>() );
}
示例12: Shared
public void Shared()
{
var parts = new[] { typeof(IHelloWorldShared), typeof(HelloWorldShared) }.AsApplicationParts();
var container = new ContainerConfiguration().WithParts( parts.ToArray(), ConventionBuilderFactory.Default.Get() ).CreateContainer();
var export = container.GetExport<IHelloWorldShared>();
Assert.IsType<HelloWorldShared>( export );
Assert.Same( export, container.GetExport<IHelloWorldShared>() );
Assert.Same( container.GetExport<HelloWorldShared>(), container.GetExport<HelloWorldShared>() );
Assert.Same( container.GetExport<HelloWorldShared>(), container.GetExport<IHelloWorldShared>() );
}
示例13: GetCompositionOperation
public override Func<Tuple<object, Action>> GetCompositionOperation()
{
var container = new ContainerConfiguration()
.WithParts(new[]{
typeof(WebServer),
typeof(Web.OperationRoot),
typeof(Web.GlobalA),
typeof(Web.GlobalB),
typeof(Web.Transient),
typeof(Web.Wide),
typeof(Web.A),
typeof(Web.B),
typeof(Web.Long),
typeof(Web.TailA),
typeof(Web.TailB),
typeof(Web.TailC)})
.CreateContainer();
var sf = container.GetExport<WebServer>().WebScopeFactory;
return () =>
{
var x = sf.CreateExport();
return Tuple.Create<object, Action>(x.Value, x.Dispose);
};
}
示例14: WithoutConvention
public void WithoutConvention()
{
var parts = new[] { typeof(IHelloWorld), typeof(HelloWorld) }.AsApplicationParts();
var container = new ContainerConfiguration().WithParts( parts.ToArray() ).CreateContainer();
Assert.Throws<CompositionFailedException>( () => container.GetExport<IHelloWorld>() );
}
示例15: UnsupportedMetadataViewMessageIsInformative
public void UnsupportedMetadataViewMessageIsInformative()
{
var cc = new ContainerConfiguration().WithParts(typeof(ImportsWithMetadataInterface), typeof(ExportsWithMetadata)).CreateContainer();
var x = Assert.Throws<CompositionFailedException>(() => cc.GetExport<ImportsWithMetadataInterface>());
Assert.Equal("The type 'INamed' cannot be used as a metadata view. A metadata view must be a concrete class with a parameterless or dictionary constructor.", x.Message);
}