Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor - private component

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?

like image 370
imb13 Avatar asked Apr 02 '20 21:04

imb13


1 Answers

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'.

like image 139
Neil W Avatar answered Sep 30 '22 22:09

Neil W