ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
336 stars 33 forks source link

Updated documentation #240

Open SuperJMN opened 4 years ago

SuperJMN commented 4 years ago

For example:

How is TypesThat used? How do we correctly use ExportAssembly

More samples regarding fluent API usage.

For example, I did this:

To register all the Tools in a given assembly as Tool, so an injection like IEnumerable<Tool> works I did:

registrationBlock.Export(toolType.Assembly.ExportedTypes
        .Where(TypesThat.AreBasedOn<Tool>())
        .Where(x => !x.IsAbstract))
    .ByTypes(type => new[] { toolType });

Is there a better, simplified way to achieve that?

Another example. Does this look OK?

registrationBlock.ExportAssemblies(Assemblies.AppDomainAssemblies)
    .Where(y => typeof(ISection).IsAssignableFrom(y))
    .ByInterface<ISection>()
    .ByInterface<IBusy>()
    .ByType()
    .ExportAttributedTypes()
    .Lifestyle.Singleton();

BTW: I could collaborate with the docs, but I don't know how to do it 😥

ipjohnson commented 4 years ago

Hi José,

I’m out of town today but I’ll reply tomorrow with an in-depth answer

ipjohnson commented 4 years ago

So looking at your examples both look correct. I think ultimately it really comes down to do you like using linq yourself or do you want to have the container do it for you.

sgf commented 4 years ago

that seems to Grace does not provide simplified inside the bulk registration API ?

ipjohnson commented 4 years ago

Hi @sgf

What type of simplification are you looking for?

sgf commented 4 years ago

like these: https://github.com/z4kn4fein/stashbox/wiki/Assembly-registration https://github.com/seesharper/LightInject#assembly-scanning

In fact, it's not essential, but if any easier

ipjohnson commented 4 years ago

@sgf there are a number of export functions that work on lists of types that are quite similar to what you posted for example ExportAssemblyContaining<T>.

What are you looking for specifically?

sgf commented 4 years ago

@sgf there are a number of export functions that work on lists of types that are quite similar to what you posted for example ExportAssemblyContaining<T>.

What are you looking for specifically?

I'm sorry, I didn't find it in the documentation. So I thought your project was not supported. Now, you tell me that ExportAssemblyContaining<T>, thank you very much.

It seems that the problem I raised does not exist. 😂