This project is read-only.

Using EnableFeatures(), DisableFeatures() inside a module

Topics: Writing modules
Jan 15, 2014 at 7:48 PM
Edited Jan 15, 2014 at 7:51 PM
I have an /Admin/MyModule page with a button on it, when pushed it calls an Ajax Controller which calls:
_features.EnableFeatures(new[] {"Orchard.Search.MediaLibrary"}, true);
It seems to work, but then the next page load fails with a Lifetime scope issue. The site then hangs.

I tried wrapping it in a lifetime scope, but it still fails on the next page load.
using (new TransactionScope(TransactionScopeOption.RequiresNew))
    _features.EnableFeatures(new[] {"Orchard.Search.MediaLibrary"}, true);
Is it possible to call code like this in a controller, or does it HAVE to be in a Migration?
Jan 15, 2014 at 7:52 PM
Can't do it right now by myself but you could look at what the Features controller is actually doing when it enables features. Use the exact same code and it should just work.

Another location to look at is in the Features recipe step which can do it too.
Jan 16, 2014 at 12:59 AM
Edited Jan 16, 2014 at 2:03 AM
I looked at both Recipe and Features controller and they are both simply calling the same method that I'm calling.

I think it was something colliding with SignalR. I removed that and now it seems to be working.