diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dce44f287..61bfb88aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,19 +1,29 @@ name: Pure.DI check -on: [push] +on: [ push ] jobs: build: runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Setup dotnet - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '8.0.x' - - name: Build and check - run: dotnet run --project ./build -- check + steps: + - uses: actions/checkout@v4 + + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + #- name: Build and check + #run: dotnet run --project ./build -- check + + - name: Publish Blazor example + run: dotnet run --project ./build -- publish + + - name: Commit wwwroot to GitHub Pages + uses: JamesIves/github-pages-deploy-action@3.7.1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages + FOLDER: samples/BlazorWebAssemblyApp/bin/wwwroot diff --git a/.gitignore b/.gitignore index b6ba230ca..ec2c6cdd8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ benchmarks/data/results/*.md _ReSharper.Caches/ .idea .logs + diff --git a/.run/Publish Blazor example.run.xml b/.run/Publish Blazor example.run.xml new file mode 100644 index 000000000..a10e319e5 --- /dev/null +++ b/.run/Publish Blazor example.run.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs index e37959403..45dc9e32c 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -2,20 +2,24 @@ DI.Setup(nameof(Composition)) .Root("RootTarget") + .DefaultLifetime(Lifetime.PerBlock) - .Bind().To() - .Bind().To() + + .Bind().To() + .Bind().To() .Bind().To(_ => GetService()) - .Bind().To(_ => GetService()) + .Bind().To(_ => GetService()) + // Targets - .Bind>(typeof(GeneratorTarget)).To() - .Bind>>(typeof(LibrariesTarget)).To() - .Bind>>(typeof(CompatibilityCheckTarget)).To() - .Bind>>(typeof(PackTarget)).To() - .Bind(typeof(ReadmeTarget)).To() - .Bind>(typeof(BenchmarksTarget)).To() - .Bind(typeof(DeployTarget)).To() - .Bind(typeof(TemplateTarget)).To() - .Bind(typeof(UpdateTarget)).To(); + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To() + .Bind(Tag.Type).To(); return await new Composition().RootTarget.RunAsync(CancellationToken.None); \ No newline at end of file diff --git a/build/PublishBlazorTarget.cs b/build/PublishBlazorTarget.cs new file mode 100644 index 000000000..dd14694d1 --- /dev/null +++ b/build/PublishBlazorTarget.cs @@ -0,0 +1,46 @@ +// ReSharper disable StringLiteralTypo +// ReSharper disable HeapView.DelegateAllocation +// ReSharper disable HeapView.ClosureAllocation +// ReSharper disable ClassNeverInstantiated.Global +// ReSharper disable ReturnTypeCanBeEnumerable.Local +// ReSharper disable InvertIf + +namespace Build; + +internal class PublishBlazorTarget( + Commands commands) + : IInitializable, ITarget +{ + public Task InitializeAsync() => commands.Register( + this, + "Publish balazor web sssembly example", + "publish", + "pb"); + + [SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] + public async Task RunAsync(CancellationToken cancellationToken) + { + var projectPath = Path.Combine("samples", "BlazorWebAssemblyApp"); + var publishPath = Path.Combine(projectPath, "bin"); + var rootPath = Path.Combine(publishPath, "wwwroot"); + var result = await new DotNetPublish() + .WithProject(projectPath) + .WithConfiguration("Release") + .WithOutput(publishPath) + .RunAsync(cancellationToken: cancellationToken); + + // Change the base-tag in index.html from '/' to 'BlazorWebAssemblyApp' to match GitHub Pages repository subdirectory + var indexFile = Path.Combine(rootPath, "index.html"); + var indexContent = await File.ReadAllTextAsync(indexFile, cancellationToken); + indexContent = indexContent.Replace("""""", """"""); + await File.WriteAllTextAsync(indexFile, indexContent, cancellationToken); + + // Copy index.html to 404.html to serve the same file when a file is not found + File.Copy(indexFile, Path.Combine(rootPath, "404.html")); + + // Add .nojekyll file to tell GitHub pages to not treat this as a Jekyll project. (Allow files and folders starting with an underscore) + await File.AppendAllTextAsync(Path.Combine(rootPath, ".nojekyll"), "", cancellationToken); + + return result ?? 1; + } +} \ No newline at end of file diff --git a/readme/BlazorWebAssemblyAppPageTemplate.md b/readme/BlazorWebAssemblyAppPageTemplate.md index e629c4a95..098323f30 100644 --- a/readme/BlazorWebAssemblyAppPageTemplate.md +++ b/readme/BlazorWebAssemblyAppPageTemplate.md @@ -2,6 +2,8 @@ [![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](/samples/BlazorServerApp) +[Here's an example](https://devteam.github.io/Pure.DI/) on github.io + This example demonstrates the creation of a [Blazor WebAssembly](https://learn.microsoft.com/en-us/aspnet/core/blazor/hosting-models#blazor-webassembly) application in the pure DI paradigm using the _Pure.DI_ code generator. Composition setup file is [Composition.cs](/samples/BlazorWebAssemblyApp/Composition.cs): diff --git a/samples/BlazorServerApp/Pages/Index.razor b/samples/BlazorServerApp/Pages/Index.razor index e829eb843..c061668f7 100644 --- a/samples/BlazorServerApp/Pages/Index.razor +++ b/samples/BlazorServerApp/Pages/Index.razor @@ -7,7 +7,7 @@

Hello, world!

-Welcome to your new app. +Welcome to your Pure.DI Blazor server example.
diff --git a/samples/BlazorServerApp/Shared/MainLayout.razor b/samples/BlazorServerApp/Shared/MainLayout.razor index a37cb45bd..85208aef8 100644 --- a/samples/BlazorServerApp/Shared/MainLayout.razor +++ b/samples/BlazorServerApp/Shared/MainLayout.razor @@ -1,6 +1,6 @@ @inherits LayoutComponentBase -BlazorServerApp +Pure.DI Blazor server example