Skip to content

Autoexport all types by interface by specific key #205

Description

@mcdis

Hi!

Can you help me with this scenario...
I want to scan all types in specific assembly and export all types which impl specific interface...but I want to export by key which defined thru attribute. And I want to export with the specific lifestyle.

[Foo("a")]
class A: IExportInterface    {}

[Foo("b")]
class B: IExportInterface    {}

// ... after apply some grace magick ...
container.Locate<IExportInterface>(withKey: "a") // Yeah, It`a instance of A
container.Locate<IExportInterface>(withKey: "b") // Yeah, It`a instance of B

Some optimize and degree of freedom requirements:

  • export types only from specific assembly;
  • key provider delegate: string ResolveKey(Type _type)

ExportAssemblyContaining?

I can suggest some export method like:

_.ExportAssemblyContaining<IHofChangeProcessor>().ByKey(_type=>_type.GetTypeInfo().GetCustomAttribute<FooAttribute>().Name).Lifestyle.Singleton();

_.ExportAssemblyContaining<IHofChangeProcessor>(typeof(Anchor).Assembly).ByKey(_type=>_type.GetTypeInfo().GetCustomAttribute<FooAttribute>().Name).Lifestyle.Singleton();

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions