webadvanced / Structuremap.MVC5

Apache License 2.0
21 stars 9 forks source link

DefaultRegistry should not be added explicitly #6

Open MelGrubb opened 9 years ago

MelGrubb commented 9 years ago

The IoC class explicitly registers DefaultRegistry rather than calling a scanner to look for all registries. While the DefaultRegistry has a commented out place to put your explicit type registrations (For.Use), this still means that you have to edit DefaultRegistry in order to add classes, or to tell it to look for other registries. This causes a manual merge issue if the StructureMap.MVC package is ever updated.

Instead of explicitly adding just the one registry (DefaultRegistry), if IoC.Initialize scanned the calling assembly looking for other registries then it would pick up on DefaultRegistry, as well as any others that are added to the project. In this way, developers could add their configurations to the mix without having to edit any of the files that came from the package, thus eliminating future merge/overwrite issues. In fact, you can eliminate DefaultRegistry entirely and absorb it back into IoC.Initialize.

Here is my current IoC.Initialize method, for example: public static IContainer Initialize() { return new Container(c => c.Scan(scan => { scan.TheCallingAssembly(); scan.LookForRegistries(); scan.WithDefaultConventions(); scan.With(new ControllerConvention()); })); }

valmont commented 9 years ago

Great point. Will update this in the next release.