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

Add support for searching registrations in assemblies #10

Open
ArnaudB88 opened this issue Oct 17, 2018 · 2 comments
Open

Add support for searching registrations in assemblies #10

ArnaudB88 opened this issue Oct 17, 2018 · 2 comments
Labels
Enhancement 🔨 Improvement of existing features Question ❔ Issue is a question

Comments

@ArnaudB88
Copy link

Support for searching 'registration classes' would be helpful when configuring registrations in a big solution. Registration-by-convention is a big help for general registrations, but custom ones should be written separately. In our solution, we have written such custom registrations in each project in a separate class. To avoid calling those classes manually, auto-search for these 'registration classes' would be helpful.
This functionality can be found in StructureMap:
http://structuremap.github.io/registration/auto-registration-and-conventions/
(See 'Scan for Registries')

How should it look like for us (the users)?

  1. We can create classes which inherit from a unity class (eg. Registry) with one method (or constructor). Within that method, container registrations can be written. This can be useful if registrations-by-convention should be overwritten with a custom registration (for eg. decorators/interceptors)
    Example:
public class FooRegistry : Registry
    {
        public override void Register(IUnityContainer container, Func<LifetimeManager> createLifetimeManager)
        {
            container.RegisterType<IBar, Bar>(createLifetimeManager());
        }
    }
  1. It is possible to specify that unity would search for these type of classes.
    Example:
//separate method
container.SearchForRegistries(lifetimeManager);
//or expanding existing method
container.RegisterTypes(....., SearchForRegistries: true);
@ENikS ENikS transferred this issue from unitycontainer/unity Dec 3, 2018
@ENikS
Copy link
Contributor

ENikS commented Dec 6, 2018

I been thinking about adopting Microsoft's convention from either MEF, MEF2 or both. It has all the necessary classes and attributes already built into the framework and should be easily adopted. I am trying to avoid inventing new ways of doing well known things.

Perhaps I could add an attribute to find and execute a static method on static class to do something like you propose. I need more info on that.

@ENikS ENikS added Enhancement 🔨 Improvement of existing features Question ❔ Issue is a question labels Dec 6, 2018
@ArnaudB88
Copy link
Author

I don't have any experience with MEF, but I agree that this functionality should not be 'a new invention'.
I got my thoughts from the (deprecated) library StructureMap which we also use on some projects. A possible implementation for this functionality can also be found there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 🔨 Improvement of existing features Question ❔ Issue is a question
Projects
None yet
Development

No branches or pull requests

2 participants