Skip to content

Commit

Permalink
move document to packages
Browse files Browse the repository at this point in the history
/pkgs
  • Loading branch information
StardustDL committed May 30, 2021
1 parent 4cf3f5c commit aed38d1
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 221 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
- name: Install docfx
run: choco install docfx -y
- name: Integration
Expand All @@ -39,6 +42,9 @@ jobs:
uses: actions/checkout@v2.3.4
with:
persist-credentials: false
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
- name: Download artifacts
uses: actions/download-artifact@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
uses: actions/checkout@v2.3.4
with:
persist-credentials: false
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
- name: Install docfx
run: choco install docfx -y
- name: Build and Deploy packages
Expand Down
226 changes: 7 additions & 219 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,241 +28,29 @@

### Use modules

1. Register modules.

For general modules:

```cs
services.AddModules(builder => {
builder.AddModule<FooModule>();
});
```

2. Configure the module initilizing & shutdown.

```cs
var host = services.GetModuleHost();
await host.Initialize();

// do something
await host.Shutdown();

// Or use context:
// context: IServiceProvider services (provided by package Modulight.Modules.Core)
await using var _ = await services.UseModuleHost();

// do something
```

Or use extension methods for hosting:

```cs
// ASP.NET hosting. (provided by package Modulight.Modules.Server.AspNet)
// in Program: Task Main(string[] args)
await CreateHostBuilder(args).Build().RunAsyncWithModules();

// WebAssembly hosting. (provided by package Modulight.Modules.Client.RazorComponents)
// in Program: Task Main(string[] args)
await builder.Build().RunAsyncWithModules();
```
See [README](./src/Modulight.Modules.Core/README.md) for details.

### Addition steps

#### Use Command line modules

[![](https://buildstats.info/nuget/Modulight.Modules.CommandLine)](https://www.nuget.org/packages/Modulight.Modules.CommandLine/)

```cs
class Program
{
public static async Task Main(string[] args) => await CreateHostBuilder(args).RunConsoleAsyncWithModules();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddModules(builder =>
{
builder.UseCommandLineModules().AddModule<AModule>();
});
});
}

[Command]
public class LogCommand : ModuleCommand<AModule>
{
public LogCommand(AModule module) : base(module)
{
}

// Order: 0
[CommandParameter(0, Description = "Value whose logarithm is to be found.")]
public double Value { get; init; }

// Name: --base
// Short name: -b
[CommandOption("base", 'b', Description = "Logarithm base.")]
public double Base { get; init; } = 10;

protected override ValueTask ExecuteAsync(IConsole console, CancellationToken cancellationToken = default)
{
var result = Math.Log(Value, Base);
console.Output.WriteLine(result);
console.Output.WriteLine($"From Module {Module.Manifest.DisplayName}.");

return default;
}
}

[CommandFrom(typeof(LogCommand))]
public class AModule : CommandLineModule
{
public AModule(IModuleHost host) : base(host)
{
}
}
```

A [Sample startup](https://github.com/StardustDL/modulight/blob/master/test/Test.CommandLine/Program.cs).
See [README](./src/Modulight.Modules.CommandLine/README.md) for details.

#### Use Razor component modules

[![](https://buildstats.info/nuget/Modulight.Modules.Client.RazorComponents)](https://www.nuget.org/packages/Modulight.Modules.Client.RazorComponents/)

Modulight provides a place to unify resources, and it can be used to make Razor component library easy to use and manage. The user needn't to take care of related services and `<script>` or `<link>` tags in `index.html`.

```cs
// in Startup: void ConfigureServices(ISeviceCollection services)
services.AddModules(builder => {
builder.UseRazorComponentClientModules().AddModule<FooModule>();
});
```

For razor components, add `ResourceDeclare` component to App.razor to load UI resources.

```razor
<Modulight.Modules.Client.RazorComponents.UI.ResourceDeclare />
```

This component will find all resources and global components defined in modules, and render HTML tags for them.

You can also use the following codes to load resources manually (needs IJSRuntime).

```cs
// WebAssemblyHost host;
await host.Services.GetRazorComponentClientModuleCollection().LoadResources();
```

### Use Blazor UI hosting template
See [README](./src/Modulight.Modules.Client.RazorComponents/README.md) for details.

Modulight provide a template project for Blazor hosting with Razor Component Client modules.
#### Use Blazor UI hosting template

Use the package [Modulight.UI.Blazor ![](https://buildstats.info/nuget/Modulight.UI.Blazor?includePreReleases=true)](https://www.nuget.org/packages/Modulight.UI.Blazor/) to try it.

It provides a navigation layout generated by client modules.

First implement a custom Blazor UI provider.

```cs
class CustomBlazorUIProvider : BlazorUIProvider
{
public CustomBlazorUIProvider(IRazorComponentClientModuleCollection razorComponentClientModuleCollection) : base(razorComponentClientModuleCollection)
{
}
}
```

Then use the provider.

#### In WebAssembly

```cs
builder.Services.AddModules(builder =>
{
builder.UseRazorComponentClientModules().AddBlazorUI<CustomBlazorUIProvider>();
});
```

A [Sample startup](https://github.com/StardustDL/modulight/blob/master/test/Test.Modulights.UI.Wasm/Program.cs).

#### In ASP.NET hosting

It needs the package [Modulight.UI.Blazor.Hosting ![](https://buildstats.info/nuget/Modulight.UI.Blazor.Hosting?includePreReleases=true)](https://www.nuget.org/packages/Modulight.UI.Blazor.Hosting/) to support prerendering.

```cs
// void ConfigureServices(IServiceCollection services)
services.AddModules(builder =>
{
builder.UseRazorComponentClientModules().AddServerSideBlazorUI<CustomBlazorUIProvider>();
// builder.UseRazorComponentClientModules().AddClientSideBlazorUI<CustomBlazorUIProvider>();
});

// void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseAspNetServerModuleMiddlewares();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapAspNetServerModuleEndpoints();
});

// in Program: Task Main(string[] args)
await CreateHostBuilder(args).Build().RunAsyncWithModules();
```

A [Sample startup](https://github.com/StardustDL/modulight/blob/master/test/Test.Modulights.UI/Startup.cs).
See [README](./src/Modulight.UI.Blazor/README.md) for details.

#### Use ASP.NET modules

[![](https://buildstats.info/nuget/Modulight.Modules.Server.AspNet)](https://www.nuget.org/packages/Modulight.Modules.Server.AspNet/)

```cs
// in Startup: void ConfigureServices(ISeviceCollection services)
services.AddModules(builder => {
builder.UseAspNetServerModules().AddModule<FooModule>();
});

// in Startup: void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseAspNetServerModuleMiddlewares();

app.UseEndpoints(endpoints =>
{
endpoints.MapAspNetServerModuleEndpoints();
});
```
See [README](./src/Modulight.Modules.Server.AspNet/README.md) for details.

#### Use GraphQL modules

[![](https://buildstats.info/nuget/Modulight.Modules.Server.GraphQL)](https://www.nuget.org/packages/Modulight.Modules.Server.GraphQL/)

```cs
// in Startup: void ConfigureServices(ISeviceCollection services)
services.AddModules(builder => {
builder.UseGraphQLServerModules().AddModule<FooModule>();
});

// in Startup: void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseEndpoints(endpoints =>
{
// modules mapper
endpoints.MapGraphQLServerModuleEndpoints(postMapEndpoint: (module, builder) =>
{
builder.RequireCors(cors =>
{
cors.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
});
});
});
```
See [README](./src/Modulight.Modules.Server.GraphQL/README.md) for details.

## Example codes

Expand Down
26 changes: 26 additions & 0 deletions src/Modulight.Modules.Client.RazorComponents/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# Modulight.Modules.Client.RazorComponents

[![](https://buildstats.info/nuget/Modulight.Modules.Client.RazorComponents)](https://www.nuget.org/packages/Modulight.Modules.Client.RazorComponents/)

Modulight provides a place to unify resources, and it can be used to make Razor component library easy to use and manage. The user needn't to take care of related services and `<script>` or `<link>` tags in `index.html`.

```cs
// in Startup: void ConfigureServices(ISeviceCollection services)
services.AddModules(builder => {
builder.UseRazorComponentClientModules().AddModule<FooModule>();
});
```

For razor components, add `ResourceDeclare` component to App.razor to load UI resources.

```razor
<Modulight.Modules.Client.RazorComponents.UI.ResourceDeclare />
```

This component will find all resources and global components defined in modules, and render HTML tags for them.

You can also use the following codes to load resources manually (needs IJSRuntime).

```cs
// WebAssemblyHost host;
await host.Services.GetRazorComponentClientModuleCollection().LoadResources();
```
54 changes: 54 additions & 0 deletions src/Modulight.Modules.CommandLine/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
# Modulight.Modules.CommandLine

[![](https://buildstats.info/nuget/Modulight.Modules.CommandLine)](https://www.nuget.org/packages/Modulight.Modules.CommandLine/)

```cs
class Program
{
public static async Task Main(string[] args) => await CreateHostBuilder(args).RunConsoleAsyncWithModules();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddModules(builder =>
{
builder.UseCommandLineModules().AddModule<AModule>();
});
});
}

[Command]
public class LogCommand : ModuleCommand<AModule>
{
public LogCommand(AModule module) : base(module)
{
}

// Order: 0
[CommandParameter(0, Description = "Value whose logarithm is to be found.")]
public double Value { get; init; }

// Name: --base
// Short name: -b
[CommandOption("base", 'b', Description = "Logarithm base.")]
public double Base { get; init; } = 10;

protected override ValueTask ExecuteAsync(IConsole console, CancellationToken cancellationToken = default)
{
var result = Math.Log(Value, Base);
console.Output.WriteLine(result);
console.Output.WriteLine($"From Module {Module.Manifest.DisplayName}.");

return default;
}
}

[CommandFrom(typeof(LogCommand))]
public class AModule : CommandLineModule
{
public AModule(IModuleHost host) : base(host)
{
}
}
```

A [Sample startup](https://github.com/StardustDL/modulight/blob/master/test/Test.CommandLine/Program.cs).
Loading

0 comments on commit aed38d1

Please sign in to comment.