Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no way of inspecting the registered types programatically #84

Open
bitbonk opened this issue Nov 11, 2015 · 2 comments
Open

There is no way of inspecting the registered types programatically #84

bitbonk opened this issue Nov 11, 2015 · 2 comments

Comments

@bitbonk
Copy link

bitbonk commented Nov 11, 2015

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.

@grumpydev
Copy link
Owner

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.

@bitbonk
Copy link
Author

bitbonk commented Nov 11, 2015

What is this doing that the existing AutoRegister doesn't already do?

  1. It doesn't leave the existing registrations untouched.
  2. 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();
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants