ipjohnson / Grace

Grace is a feature rich dependency injection container library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Check if actual type is exported

silkfire opened this issue · comments

It is today possible to check whether a class has already been exported with the IsExported method. Unfortunately, it is a bit limited as it isn't able to check what actual type has been registered, it's only based on the selected As() type. Could we implement an overload of the method that allows this?

This is related to the following scenario:

Let's say I want to export a set of types implementing an interface. All of these types have an empty public constructor (easy to resolve), except for one of the types.
So I first perform a special registration for that type, as it has a string dependency.
But when I want to resolve a list of types based on that interface, I get an error because the type with the string dependency can't be resolved. Is there any way for it to not be exported? Can it check that the actual type already has been registered and ignore it?

// Special registration for class with string dependency
_.Export<MyClassSpecial>().As<IMyInterface>().WithCtorParam(() => "param")).Lifestyle.Singleton();

// Export all types implementing IMyInterface as IMyInterface (but ignore above type, no duplicate registration)
_.Export(....)

I can see the value in something like this but i don’t know if I’ll have time in the near future to address this properly. It will probably be a couple months before I can dedicate time to major features.