CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.05k stars 172 forks source link

Nested CarterModules are not found when using Default AddCarter() #259

Closed ggmueller closed 2 years ago

ggmueller commented 3 years ago

When using the following configuration in the Startup: services.AddCarter() Carter does not consider Nested Classes as modules that it configures.

Registering nested classes explicitly works.

It seems like this is due to this LINQ condition in the code:

modules = assemblies.SelectMany(x => x.DefinedTypes
                    .Where(t =>
                        !t.IsAbstract &&
                        typeof(CarterModule).IsAssignableFrom(t) &&
                        t != typeof(CarterModule) &&
                        t.IsPublic
                    ));

In a quick test changing this piece of code to also consider type with t.IsNestedPublic in the debugger also registered the nested classes.

Is the restriction of types to only outer types intended?

JoeStead commented 3 years ago

No reason that I'm aware of. It's a bit of an interesting setup, but if it works... it works

jchannon commented 2 years ago

Carter 6 will use ICarterModule

yegorandrosov commented 9 months ago

still does not work, DependencyContextAssemblyCatalog.GetAssemblies does not include nested classes