Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleInjector Unbind/Rebind

I have a core set of libraries that are delivered and work "out of the box". Meaning that the services are all wired up inside. I would like to have the ability to modify the core library (without modifying the library itself).

With that said, is there an Unbind/Rebind support in SimpleInjector? I didn't see any publicly visible methods on the container. I did find a private dictionary of registrations that I can get to with reflection.

Does anyone see a reason why I can't remove items from this private dictionary (to then re-add) at runtime with reflection? Is there a method I am missing?

like image 690
Paul Knopf Avatar asked Jan 29 '13 14:01

Paul Knopf


1 Answers

Removal of registrations is not possible. Overriding registrations however is. You will have to flag the container to allow this:

var container = new Container();

container.Register<IService, FirstService>();

container.Options.AllowOverridingRegistrations = true;

// Replaces the former registration
container.Register<IService, AnotherService>();
like image 75
Steven Avatar answered Sep 28 '22 05:09

Steven