I have quite a big project with various RCLs and each contains a myriad of components that end up being consumed from the root app.
The problem im finding is as I get more components I need to change how they are structured on the file system, which in turn means every project that uses them needs to update the _imports.razor
to have the SPECIFIC namespace where the component lives, but its getting really tiresome every time I want to move a component about I need to refactor 5 different projects imports to get it working again.
So is there a way to just have it bulk import off a root namespace or some other mechanism to be able to get away from explicit granular namespacing?
Here is an example of what I mean:
@using Foo.Core.Components;
@using Foo.Core.Components.Elements;
@using Foo.Core.Components.Elements.Select;
@using Foo.Core.Components.Tasks;
@using Foo.Core.Components.Tasks.Utility;
@using Foo.Core.Components.Triggers;
@using Foo.Core.Components.Triggers.Utility;
That is just a small example and that is in multiple projects and they have their own namespaces etc so its all a bit unmanageable at scale, I was hoping I could do something like:
@using Foo.Core.Components.*;
Or some other mechanism to achieve the same thing, as this way the file system layout of the components would have no bearing on their importing.
== Update 1 ==
Just to provide some clarity, there is a similar question here Importing nested namespaces automatically in C# however this is using c# syntax not razor syntax
Given that this razor has a lot of helper methods and is processed differently to regular C# the question was more wondering if there was any special razor helpers/syntax to allow us to do it, regardless of the restrictions of normal c# files.
It seems like there isnt but for anyone else coming here there are 2 work arounds I have used to date:
Give each component a MANUAL namespace i.e
@namespace Foo.Core.Component
then it doesnt matter what folder structure its in, however this causes issues if you use spiffy refactoring tools as they will try to correct the namespace for you constantly.Turning off namespace provider options for folders, this one is the nicer way of doing it as it doesnt confuse the refactoring tools, however it needs everyone understanding that each folder within there ideally needs to manually have namespace provider turned off.
This was why I was wondering if there was a 3rd option that would allow us to deal with it at namespace level rather than in the component/projects.