Deprecate Container.RegisterPackages() in SimpleInjector.Packaging #372

Open
dotnetjunkie opened this Issue Feb 4, 2017 · 0 comments

Projects

None yet

1 participant

@dotnetjunkie
Collaborator

The SimpleInjector.Packaging package contains two overloads for RegisterPackages where one accepts a list of Assembly instances, while the second doesn't. The latter method will go through all assemblies that are actively loaded in the app domain at that particular moment to find any IPackage implementations.

The use of AppDomain.GetAssemblies() to get a list of assemblies however, is fragile, because only assemblies are returned that are loaded at that point in time. There could be many other referenced assemblies and assemblies that are unregistered, but dropped-in into the application's /bin folder. Those are not always picked up.

Especially referenced assemblies cause a problem, because the RegisterPackages method is called during application startup. Small seemingly unrelated changes in the application start-up code could change whether or not referenced assemblies are actually loaded.

This behavior is problematic, especially for RegisterPackages, since it most obvious use case is to load packages from all over the place.

From that point of view, the use of the container.RegisterPackages() overload is problematic and should therefore be deprecated.

Instead, developers should always explicitly pass in the list of required assemblies onto the RegisterPackager(Container, IEnumerable<Assembly>) overload. This allows the user to pass in a fixed list of assemblies (that are guaranteed to be loaded at that point in time) or load assemblies from disk from the /bin or a possible /plugin directory instead.

@dotnetjunkie dotnetjunkie added this to the v4 milestone Feb 4, 2017
@dotnetjunkie dotnetjunkie self-assigned this Feb 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment