Skip to content

Commit

Permalink
Add wiki service configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
WilStead committed Dec 4, 2024
1 parent 961b62c commit db65c6c
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: publish
env:
VERSION: '0.11.2-preview'
VERSION: '0.11.3-preview'
PRERELEASE: true
on:
push:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ In order to use Tavenem.Wiki.Blazor, the following steps should be taken:
When providing a configuration function (rather than a preconfigured options instance) the following additional properties are available:
- `ArticleRenderManager`: an instance of `IArticleRenderManager`. The overloads of `ConfigureArticleRenderManager` also allow configuring this from dependency injection. If omitted, an instance of the default `ArticleRenderManager` will be used, which always returns `null` for all members.
- `OfflineManager`: an instance of `IOfflineManager`. The overloads of `ConfigureOfflineManager` also allow configuring this from dependency injection. If omitted, an instance of the default `OfflineManager` will be used, which always returns `false` for all members.
- `PageManager`: an instance of `IPageManager`. The overloads of `ConfigurePageManager` also allow configuring this from dependency injection. If omitted, an instance of the default `PageManager` will be used, which performs no actions.
- `PermissionManager`: an instance of `IPermissionManager`. The overloads of `ConfigurePermissionManager` also allow configuring this from dependency injection. If omitted, an instance of the default `PermissionManager` will be used, which which always returns `null`.
1. Add a page with the following content to your client:
```csharp
@page "/wiki/{*route}"
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.11.3-preview
### Added
- Wiki service configuration options

## 0.11.2-preview
### Removed
- Obsolete `DataStore` property on `WikiBlazorOptions`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Tavenem.Wiki.Blazor.Example.Client.Services;
using Tavenem.Wiki.Blazor.Example.Components;
using Tavenem.Wiki.Blazor.Example.Services;
using Tavenem.Wiki.Services;

var builder = WebApplication.CreateBuilder(args);

Expand Down
1 change: 1 addition & 0 deletions sample/WebAssembly Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Tavenem.Wiki.Blazor.Sample;
using Tavenem.Wiki.Blazor.Sample.Services;
using Tavenem.Wiki.Blazor.Sample.Shared;
using Tavenem.Wiki.Services;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
Expand Down
155 changes: 155 additions & 0 deletions src/Client/Configuration/WikiBlazorClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;
using Tavenem.Wiki.Blazor.Client.Services;
using Tavenem.Wiki.Services;

namespace Tavenem.Wiki.Blazor.Client.Configuration;

Expand All @@ -21,6 +22,18 @@ public class WikiBlazorClientOptions() : WikiBlazorOptions
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
private Type? _offlineManagerType;

private IPageManager? _pageManager;
private Func<IServiceProvider, IPageManager>? _pageManagerConfig;

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
private Type? _pageManagerType;

private IPermissionManager? _permissionManager;
private Func<IServiceProvider, IPermissionManager>? _permissionManagerConfig;

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
private Type? _permissionManagerType;

/// <summary>
/// <para>
/// Supply an instance of <see cref="IArticleRenderManager"/>.
Expand Down Expand Up @@ -59,6 +72,44 @@ public IOfflineManager? OfflineManager
}
}

/// <summary>
/// <para>
/// Supply an instance of <see cref="IPageManager"/>.
/// </para>
/// <para>
/// May be omitted to use the default <see cref="Tavenem.Wiki.Services.PageManager"/>.
/// </para>
/// </summary>
public IPageManager? PageManager
{
get => _pageManager;
set
{
_pageManager = value;
_pageManagerConfig = null;
_pageManagerType = null;
}
}

/// <summary>
/// <para>
/// Supply an instance of <see cref="IPermissionManager"/>.
/// </para>
/// <para>
/// May be omitted to use the default <see cref="Tavenem.Wiki.Services.PermissionManager"/>.
/// </para>
/// </summary>
public IPermissionManager? PermissionManager
{
get => _permissionManager;
set
{
_permissionManager = value;
_permissionManagerConfig = null;
_permissionManagerType = null;
}
}

/// <summary>
/// Constructs a new instance of <see cref="WikiBlazorClientOptions"/>.
/// </summary>
Expand Down Expand Up @@ -114,6 +165,8 @@ public override IServiceCollection Add(IServiceCollection services)
{
AddArticleRenderManager(services);
AddOfflineManager(services);
AddPageManager(services);
AddPermissionManager(services);

return base.Add(services);
}
Expand Down Expand Up @@ -180,6 +233,68 @@ public void ConfigureOfflineManager(Func<IServiceProvider, IOfflineManager> conf
_offlineManagerType = null;
}

/// <summary>
/// <para>
/// Supply a type of <see cref="IPageManager"/>.
/// </para>
/// <para>
/// May be omitted to use the default <see cref="Tavenem.Wiki.Services.PageManager"/>.
/// </para>
/// </summary>
public void ConfigurePageManager(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type? type)
{
_pageManagerConfig = null;
_pageManager = null;
_pageManagerType = type;
}

/// <summary>
/// <para>
/// Supply a function which returns an instance of <see cref="IPageManager"/>.
/// </para>
/// <para>
/// May be omitted to use the default <see cref="Tavenem.Wiki.Services.PageManager"/>.
/// </para>
/// </summary>
public void ConfigurePageManager(Func<IServiceProvider, IPageManager> config)
{
_pageManagerConfig = config;
_pageManager = null;
_pageManagerType = null;
}

/// <summary>
/// <para>
/// Supply a type of <see cref="IPermissionManager"/>.
/// </para>
/// <para>
/// May be omitted to use the default <see cref="Tavenem.Wiki.Services.PermissionManager"/>.
/// </para>
/// </summary>
public void ConfigurePermissionManager(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type? type)
{
_permissionManagerConfig = null;
_permissionManager = null;
_permissionManagerType = type;
}

/// <summary>
/// <para>
/// Supply a function which returns an instance of <see cref="IPermissionManager"/>.
/// </para>
/// <para>
/// May be omitted to use the default <see cref="Tavenem.Wiki.Services.PermissionManager"/>.
/// </para>
/// </summary>
public void ConfigurePermissionManager(Func<IServiceProvider, IPermissionManager> config)
{
_permissionManagerConfig = config;
_permissionManager = null;
_permissionManagerType = null;
}

private void AddArticleRenderManager(IServiceCollection services)
{
if (ArticleRenderManager is not null)
Expand Down Expand Up @@ -219,4 +334,44 @@ private void AddOfflineManager(IServiceCollection services)
services.AddScoped<IOfflineManager, OfflineManager>();
}
}

private void AddPageManager(IServiceCollection services)
{
if (PageManager is not null)
{
services.AddScoped(_ => PageManager);
}
else if (_pageManagerConfig is not null)
{
services.AddScoped(_pageManagerConfig);
}
else if (_pageManagerType is not null)
{
services.AddScoped(typeof(IPageManager), _pageManagerType);
}
else
{
services.AddScoped<IPageManager, PageManager>();
}
}

private void AddPermissionManager(IServiceCollection services)
{
if (PermissionManager is not null)
{
services.AddScoped(_ => PermissionManager);
}
else if (_permissionManagerConfig is not null)
{
services.AddScoped(_permissionManagerConfig);
}
else if (_permissionManagerType is not null)
{
services.AddScoped(typeof(IPermissionManager), _permissionManagerType);
}
else
{
services.AddScoped<IPermissionManager, PermissionManager>();
}
}
}
2 changes: 1 addition & 1 deletion src/Client/Tavenem.Wiki.Blazor.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Tavenem.Blazor.Framework" Version="4.0.2" />
<PackageReference Include="Tavenem.Wiki" Version="0.28.2-preview" />
<PackageReference Include="Tavenem.Wiki" Version="0.28.3-preview" />
</ItemGroup>

<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Server/Configuration/WikiBlazorServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Tavenem.Wiki.Blazor.Client.Configuration;
using Tavenem.Wiki.Blazor.Server.Authorization;
using Tavenem.Wiki.Blazor.Services;
using Tavenem.Wiki.Services;

namespace Tavenem.Wiki.Blazor.Server.Configuration;

Expand Down

0 comments on commit db65c6c

Please sign in to comment.