-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DI dependencies of features in the same assembly are mapped to the wrong feature #15782
Comments
This came up here. |
I've reviewed the Additionally, I've taken a brief look at Given this, I'm hesitant to recommend changes to the |
Yes the solution is to use OrchardCore/src/OrchardCore/OrchardCore/Shell/Builders/ShellContainerFactory.cs Lines 150 to 158 in dc6729b
|
Oh and by the way, any implementation of |
That looks like an inconvenient API, since otherwise we only need |
Yeah it would be nice if we don't have to use Feature attribute all over the place. I agree. Can you think of a better way to associate each time with a feature? Maybe one way to eliminate the use of ITypeFeatureProvider. Or scan all the registered type when calling all the startups and assign each type to the feature if the startup. |
The public void TryAdd(Type type, IFeatureInfo feature)
{
--- _features.TryAdd(type, feature);
+++ _ = _features.AddOrUpdate(type, (t, f) => f, (curType, curFeature, newFeature) =>
+++ {
+++ // If the type is currently only mapped to the module, update it with the more specific feature.
+++ if (curFeature != newFeature &&
+++ curFeature.Extension.Manifest.ModuleInfo.Id == curFeature.Id &&
+++ curFeature.Extension.Features.Contains(newFeature))
+++ {
+++ Debug.WriteLine($"TypeFeatureProvider changed mapping of type '{curType}' from '{curFeature.Id}' to '{newFeature.Id}'.");
+++ return newFeature;
+++ }
+++
+++ return curFeature;
+++ }, feature);
} That would bring us almost there, all types are then assigned to the correct feature in the But there is also the As the |
possible solution in this comment #15793 (comment) |
Describe the bug
In case a single assembly contains several features, the dependencies added to the
ITypeFeatureProvider
may not be correct. All dependencies are added to one arbitrary feature, no matter which feature actually registers it in DI. I guess anything is added to the first feature being enabled.In turn this causes things like the
RoleUpdater
to not correctly apply default permissions, because enabling a second feature in a single module is not correctly detected.This can only be prevented, when all necessary dependencies are marked with the
FeatureAttribute
.The text was updated successfully, but these errors were encountered: