Using IFeatureManager in IFeatureEventHandler

Topics: Core, Writing modules
Feb 13, 2012 at 2:32 PM
Edited Feb 13, 2012 at 2:33 PM

I've injected IFeatureManager in a IFeatureEventHandler.

I've FeatureC which depends on FeatureB which depends on FeatureA.

I've added

        public void Disabled(Feature feature)
        {
            Debug.WriteLine("Disabled: Feature=" + feature.Descriptor.Id + " Enabled Features Count:" + _featureManager.GetEnabledFeatures().Count().ToString());
        }

When disabling Feature A I get:
Disabled: Feature=FeatureC Enabled Features Count:29
Disabled: Feature=FeatureB Enabled Features Count:29
Disabled: Feature=FeatureC Enabled Features Count:29
So the order of the events is ok, but _featureManager.GetEnabledFeatures().Count() doesn't change when a feaure is disabled. I get always the same number of enabled features.
Is assume that I need to refresh featureManager.GetEnabledFeatures, but didn't find a way to do this.
So the final question is: how can I get the actual list of EnabledFeatures in an IFeatureEventHandler?
Coordinator
Feb 13, 2012 at 10:17 PM

You could probably look at how the command-line does it: Orchard.Modules.Commands.FeatureCommands.

Feb 13, 2012 at 10:49 PM

Thank you.

I've now seen that the FeatureCommands uses _shellDescriptor.Features to detect if a feature is enabled.

But after changing

Debug.WriteLine("Disabled: Feature=" + feature.Descriptor.Id + " Enabled Features Count:" + _shellDescriptor.Features().Count().ToString());

When disabling Feature A I get:

Disabled: Feature=FeatureC Enabled Features Count:34
Disabled: Feature=FeatureB Enabled Features Count:34
Disabled: Feature=FeatureC Enabled Features Count:34

So the absolute number changes, but I'd expected to get 34, 33, 32

So it seems that I didn't find the right hint in Orchard.Modules.Commands.FeatureCommands - and still facing the problem: how can I get the actual list of EnabledFeatures in an IFeatureEventHandler?

 

Coordinator
Feb 13, 2012 at 11:59 PM

I don;t know. Maybe a caching issue.