You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a Bootstrapper class in my project I have a simple mechanism that automatically registers all interfaces found in the assemblies of the current AppDomain with concrete implementations of that interface found found in the assemblies of the current appdomain into a TinyIoC container.
Be default this autoregistration should not override/change existing registrations that already have been done prior to the AutoRegister call. Unfortunately this doesn't seem to be possible because there is no way of looking at the current registrations of the TinyIoC container (_RegisterdTypes is private).
Is there a way to inspect the current registrations? If not why not and can this feature be added? It would be very easy to implement (just a public facade around _RegisteredTypes).
Of course I could just add this myself in my local copy of TinyIoC.cs but that would break with the next update.
The text was updated successfully, but these errors were encountered:
What is this doing that the existing AutoRegister doesn't already do?
As for it being accessible, it's an internal concern of the container, but the main container class is intentionally a partial class to allow for extensions like this without touching the main cs file, so if you create another partial with the method you want it will be able to access the private _RegisteredTypes field.
What is this doing that the existing AutoRegister doesn't already do?
It doesn't leave the existing registrations untouched.
The registration rules are very specific, and I don't see how to implemenet all of them using the existing AutoRegister methods. These are the rules:
It should only look at the assemblies loaded into the current appdomain.
There are some assemblies of the current appdomain that should be ignored.
It should only register interfaces as keys (no concrete types, no abstract classes).
It sould only register interfaces as keys that are not declared in the ignored assemblies even if the found concrete implementations are declared outside the ingored assemblies.
If multiple concrete implementations are found, it should use RegisterMultiple.
Thanks for the tip with the partial classes. So I could easily implement this:
public partial class TinyIoCContainer
{
/// <summary>
/// Gets all types that are registered as keys with this container.
/// </summary>
public IEnumerable<Type> RegisterdTypes
{
get
{
return this._RegisteredTypes.Keys.Select(rt => rt.Type).Distinct();
}
}
}
In a
Bootstrapper
class in my project I have a simple mechanism that automatically registers all interfaces found in the assemblies of the current AppDomain with concrete implementations of that interface found found in the assemblies of the current appdomain into a TinyIoC container.Be default this autoregistration should not override/change existing registrations that already have been done prior to the
AutoRegister
call. Unfortunately this doesn't seem to be possible because there is no way of looking at the current registrations of the TinyIoC container (_RegisterdTypes
is private).Is there a way to inspect the current registrations? If not why not and can this feature be added? It would be very easy to implement (just a public facade around
_RegisteredTypes
).Of course I could just add this myself in my local copy of TinyIoC.cs but that would break with the next update.
The text was updated successfully, but these errors were encountered: