You can replace standard Blazor component types globally or selectively by implementing IComponentTypeSwitchBroker; use this when the replacement decision must be made by your own switch logic rather than by a column-specific component tag.
Choose the right extension method
Use EXT ComponentsBlazor when you want to place your component on a specific tagged ViewModel column. Use IComponentTypeSwitchBroker when you want to intercept the component type selected by the Blazor client and decide whether to keep it or replace it.
| Requirement | Use |
|---|---|
| Replace a component on one explicitly tagged ViewModel column | EXT ComponentsBlazor and the Blazor_Ext_Component tagged value
|
| Replace all occurrences of a standard component type, or replace it only when your own logic says so | IComponentTypeSwitchBroker
|
Implement the broker
Create a type in your Blazor component assembly that implements this interface:
public interface IComponentTypeSwitchBroker
{
Type SwitchThis(IMDCompHolder compholder, Type theType);
}
The Blazor client calls SwitchThis when it has selected a component type.
| Parameter | Meaning |
|---|---|
compholder
|
The IMDCompHolder provided for the component being rendered. Use it in your own switch logic when the holder supplies the distinction you need.
|
theType
|
The component type that the Blazor client selected before your broker applied a replacement. |
Return the type that should be rendered. When your condition does not require a replacement, return theType. This preserves the standard component for all cases that your switch logic does not explicitly handle.
public sealed class MyComponentTypeSwitchBroker : IComponentTypeSwitchBroker
{
public Type SwitchThis(IMDCompHolder compholder, Type theType)
{
// Add your switch logic here.
// Return theType for every case that should retain the standard component.
return theType;
}
}
For example, a broker can examine the supplied holder in its own logic and return a replacement component type for the cases you identify. It must return the original theType for cases outside that scope; otherwise the broker changes the rendering decision for every component it receives.
Build and make the assemblies available
Your replacement components must be Blazor WebAssembly components. Build the broker and the components it returns as part of the component assembly arrangement described in EXT ComponentsBlazor. That page also describes the required component parameters, client-side build artifacts, and the EXT_ComponentsRazor deployment location.
The broker configuration can name the main assembly followed by any additional assemblies that are needed to resolve the broker type.
Configure the broker
Set the GlobalBlazorClientComponentOverride property on SysMDrivenMiscSettingsSingleton. Specify the assembly or assemblies and the fully identified type that implements IComponentTypeSwitchBroker.
Use this semicolon-separated format:
AssemblyNameWithoutExtension;AdditionalAssemblyIfNeededWithoutExtension;AsManyAssembliesAsNeededWithoutExtension;TheTypeImplementing_IComponentTypeSwitchBroker
The final value is the type that implements the interface. Do not include .dll in assembly names.
For example, if the broker is in one assembly and has no additional assembly requirement, the configuration has two parts:
MyBlazorComponents;MyNamespace.MyComponentTypeSwitchBroker
If additional assemblies are needed, place each assembly name before the broker type:
MyBlazorComponents;MySharedComponents;MyNamespace.MyComponentTypeSwitchBroker
Verify the result
- Make the broker assembly and its required Blazor component artifacts available as described in EXT ComponentsBlazor.
- Set
GlobalBlazorClientComponentOverrideto the semicolon-separated value. - Restart the application so startup-read settings and the component configuration are applied.
- Open a Blazor client view and exercise both a case that should keep the standard component and a case that should return your replacement type.
- Check the browser console if the replacement does not render. Missing client-side component files or unresolved assemblies prevent the client from loading the component.
Scope and design guidance
A broker is global configuration, so keep its decision logic narrow and predictable. Start by returning theType by default, then add explicit replacement cases. If the requirement is limited to one ViewModel column, prefer the tagged-column approach in EXT ComponentsBlazor instead of a global broker.
Blazor client rendering requires metadata for the view. For information about the Blazor-specific view metadata endpoint, see ViewMeta.
See also
- Documentation:EXT ComponentsBlazor
- Documentation:Blazor
- Documentation:SysMDrivenMiscSettingsSingleton
- Documentation:ViewMeta
- Documentation:EXT Components
Implementing IComponentTypeSwitchBroker
Implementing IComponentTypeSwitchBroker
Implement IComponentTypeSwitchBroker to provide switch logic for replacing all or some Blazor components.
public sealed class MyComponentTypeSwitchBroker : IComponentTypeSwitchBroker
{
public Type SwitchThis(IMDCompHolder compholder, Type theType)
{
// Add switch logic here.
return theType;
}
}
The broker implementation has the following method:
Type SwitchThis(IMDCompHolder compholder, Type theType);
Configure the broker
Set GlobalBlazorClientComponentOverride in SysMDrivenMiscSettingsSingleton to the assembly and type implementing IComponentTypeSwitchBroker. Use semicolon-separated values. Assembly names are specified without the file extension.
AssemblyNameWithoutExtension;AdditionalAssemblyIfNeededWithoutExtension;AsManyAssembliesAsNeededWithoutExtension;TheTypeImplementing_IComponentTypeSwitchBroker
For custom Blazor components, see EXT ComponentsBlazor.
