Is there way to create a Blazor component private for the project that it is being used in?
For example, let's look at Razor Class Library ProjectOne
that contains two components: omponent ComponentA
and component ComponentB
. The component ComponentB
is child of component ComponentA
.
ProjectOne
structure:
ProjectOne
---- Components
---------- ComponentA.razor
---------- ComponentB.razor
There is another project which is Blazor application ProjectTwo
. There is a reference in this project to ProjectOne
. When calling component ComponentA
in razor page, the child component ComponentB
is visible and accessable as well.
Is there a way to create this child component ComponentB
internal only for project ProjectOne
where it is being used within the component ComponentA
?
As it looks like the sub-component needs to be public, rather than put it in another project, I just put it in a deeper namespace.
If the root component that I want to expose publicly is in
MyApp.Components.Widget
then I put the child components in
MyApp.Components.Widget.Internal
Achieves a similar outcome to the advice from the earlier answer without the need for another project, seeing as the best we can do is obfuscate it in lieu of making it 'internal' or 'private'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With