Including the word Features
in your project namespace breaks conventions (original) (raw)
I created a new ASP.NET Core 2.1 MVC project and named the project ASPNETCoreMVC.Features.Web
.
I added <PackageReference Include="OdeToCode.AddFeatureFolders" Version="2.0.1" />
to my .csproj
.
When I run the app it says
An unhandled exception occurred while processing the request.
InvalidOperationException: The view 'Index' was not found. The following locations were searched:
Features\Web\Features\Home\Index.cshtml
Features\Shared\Index.cshtml
\Features\Index\Home.cshtml
In this case I'd need to change FeatureFolderOptions.FeatureFolderName
to something other than Features
because
@namespace.Split('.') .SkipWhile(s => s != _folderName) .Aggregate("", Path.Combine);
is going to stop too early and create the wrong folder path.
Here is an ugly solution
.AddFeatureFolders(new FeatureFolderOptions
{
FeatureFolderName = "Features",
DeriveFeatureFolderName = model =>
{
string assemblyNamespacePrefix = $"{typeof(Startup).Namespace}.";
string @namespace = model
.ControllerType
.Namespace
.Remove(0, assemblyNamespacePrefix.Length);
string result = @namespace.Split('.')
.SkipWhile(s => s != "Features")
.Aggregate("", Path.Combine);
return result;
}
});
But maybe the best thing to do is add a disclaimer to the README.md
that your feature folder name cannot be in the project namespace?