Class ViewRouter
Default IViewRouter: shows a view by id by asking each registered IViewProvider in turn whether it owns the id, and delegating to the first that does. Engine-agnostic and unit-testable — it depends only on the provider abstraction and a log service.
Inherited Members
Namespace: Serenity.Global.Application.Services
Assembly: Serenity.Global.Application.dll
Syntax
public class ViewRouter : IViewRouter, IService, IFoundationSettings
Constructors
ViewRouter(IEnumerable<IViewProvider>, ILogService)
Creates the router over an ordered set of providers.
Declaration
public ViewRouter(IEnumerable<IViewProvider> providers, ILogService logService)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<IViewProvider> | providers | The providers consulted, in priority order, to resolve a view id. |
| ILogService | logService | Logging service. |
Properties
Guid
Declaration
public string Guid { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Id
Declaration
public string Id { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
LogService
Declaration
public ILogService LogService { get; set; }
Property Value
| Type | Description |
|---|---|
| ILogService | Gets or sets the log service for logging purposes. |
Methods
CanShowView(string)
True when some registered provider owns a view with the given id — i.e. ShowView(string) would actually show it rather than warn and no-op. Lets a caller with side effects of its own (e.g. popping navigation history before returning) verify the navigation will happen first.
Declaration
public bool CanShowView(string viewId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | viewId | The view id to test. |
Returns
| Type | Description |
|---|---|
| bool | True when the id resolves to a registered view. |
ClearCurrentView()
Forgets the tracked current view without hiding anything. Used when a subsystem (e.g. the menu
service's DeactivateMenuContext) hides the active view outside the router, so the
router's state does not go stale and cause a spurious hide on the next ShowView(string).
Declaration
public void ClearCurrentView()
HideView(string)
Hides the view with the given id via whichever provider owns it.
Declaration
public void HideView(string viewId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | viewId | The id of the view to hide. |
RegisterProvider(IViewProvider)
Registers a provider (a subsystem that owns top-level views) consulted when resolving ids.
Declaration
public void RegisterProvider(IViewProvider provider)
Parameters
| Type | Name | Description |
|---|---|---|
| IViewProvider | provider | The provider to add. |
SetInitialViewId(string)
Sets the id of the initial/root view shown by ShowInitialView().
Declaration
public void SetInitialViewId(string viewId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | viewId | The initial view id (may be a menu or a custom view). |
ShowInitialView()
Shows the configured initial/root view.
Declaration
public void ShowInitialView()
ShowView(string)
Shows the view with the given id via whichever provider owns it, first hiding the currently shown top-level view (if any and different). This is how navigation "deactivates the current view and activates the target" uniformly for menus and composite custom views.
Declaration
public void ShowView(string viewId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | viewId | The id of the view to show. |