0

After working with Ninject and SimpleInjector for years, I'm pretty used to separating my registrations into various modules which I can load based on configuration etc. Also, they extremely help to reduce the clutter of a huge wall of registration code.

public UserModule : NinjectModule {
    public override Load() {
        Kernel.Bind<IUserAuthenticationService>()...
    }
}

Does Unity support something like this? Googling and reading through the official docs brought nothing up.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
  • 1
    *Googling and reading through the official docs brought nothing up* I tried searching google, not more than one minute; I found the duplicate question. Search keyword is "unity container modules" and first hit is the duplicate link :) – Sriram Sakthivel Apr 21 '15 at 21:47
  • @SriramSakthivel lol I googled for Unity in combination with "ninject" as I didn't know Autofac also had modules. Good to know! –  Apr 21 '15 at 22:30
  • A modules/installers/registries feature is usually very useless, because in most cases you can achieve the same by extracting the relevant code to a public static class and call that class from within your main application. Modules are especially useful in cases you want to load assemblies dynamically without having a compile-time dependency, which is only useful in plugin scenarios. – Steven Apr 22 '15 at 08:19

1 Answers1

1

You could create a Unity Extension and provide registrations as part of this extension.

Container.RegisterExtension<MyModule>(...);
James Lucas
  • 2,452
  • 10
  • 15