Skip to content

Commit

Permalink
Push changes from last evening.
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Mar 23, 2022
1 parent 75faacc commit 5d57c46
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 32 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ jobs:
- name: Restore dependencies
run: |
dotnet restore ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj
dotnet restore ./src/Blazor.Serialization/Blazor.Serialization.csproj
dotnet restore ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj
dotnet restore ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj
dotnet restore ./src/Blazor.Serialization/Blazor.Serialization.csproj
dotnet restore ./src/Blazor.SessionStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj
dotnet restore ./src/Blazor.SessionStorage.Server/Blazor.LocalStorage.Server.csproj
dotnet restore ./src/Blazor.Geolocation.WebAssembly/Blazor.Geolocation.WebAssembly.csproj
dotnet restore ./src/Blazor.Geolocation.Server/Blazor.Geolocation.Server.csproj
- name: Build
run: |
dotnet build ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.Serialization/Blazor.Serialization.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.Serialization/Blazor.Serialization.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.SessionStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.SessionStorage.Server/Blazor.LocalStorage.Server.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.Geolocation.WebAssembly/Blazor.Geolocation.WebAssembly.csproj --configuration Release --no-restore
dotnet build ./src/Blazor.Geolocation.Server/Blazor.Geolocation.Server.csproj --configuration Release --no-restore
Expand All @@ -52,9 +56,11 @@ jobs:
- name: Pack
run: |
dotnet pack ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj --output packages
dotnet pack ./src/Blazor.Serialization/Blazor.Serialization.csproj --output packages
dotnet pack ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj --output packages
dotnet pack ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj --output packages
dotnet pack ./src/Blazor.Serialization/Blazor.Serialization.csproj --output packages
dotnet pack ./src/Blazor.SessionStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj --output packages
dotnet pack ./src/Blazor.SessionStorage.Server/Blazor.LocalStorage.Server.csproj --output packages
dotnet pack ./src/Blazor.Geolocation.WebAssembly/Blazor.Geolocation.WebAssembly.csproj --output packages
dotnet pack ./src/Blazor.Geolocation.Server/Blazor.Geolocation.Server.csproj --output packages
Expand All @@ -68,6 +74,12 @@ jobs:
name: Blazor.SourceGenerators.${{ steps.regex-match.outputs.match }}.nupkg
path: packages/

- name: Upload serialization package
uses: actions/upload-artifact@v2
with:
name: Blazor.Serialization.${{ steps.regex-match.outputs.match }}.nupkg
path: packages/

- name: Upload localStorage WebAssembly package
uses: actions/upload-artifact@v2
with:
Expand All @@ -80,10 +92,16 @@ jobs:
name: Blazor.LocalStorage.Server.${{ steps.regex-match.outputs.match }}.nupkg
path: packages/

- name: Upload serialization package
- name: Upload sessionStorage WebAssembly package
uses: actions/upload-artifact@v2
with:
name: Blazor.Serialization.${{ steps.regex-match.outputs.match }}.nupkg
name: Blazor.SessionStorage.WebAssembly.${{ steps.regex-match.outputs.match }}.nupkg
path: packages/

- name: Upload sessionStorage Server package
uses: actions/upload-artifact@v2
with:
name: Blazor.SessionStorage.Server.${{ steps.regex-match.outputs.match }}.nupkg
path: packages/

- name: Upload geolocation WebAssembly package
Expand Down
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ A C# source generator that creates extensions methods on the Blazor WebAssembly
|--|--|--|
| [`Blazor.SourceGenerators`](https://www.nuget.org/packages/Blazor.SourceGenerators) | [![NuGet](https://img.shields.io/nuget/v/Blazor.SourceGenerators.svg?style=flat)](https://www.nuget.org/packages/Blazor.SourceGenerators) | Core source generator library. |
| [`Blazor.Serialization`](https://www.nuget.org/packages/Blazor.Serialization) | [![NuGet](https://img.shields.io/nuget/v/Blazor.Serialization.svg?style=flat)](https://www.nuget.org/packages/Blazor.Serialization) | Common serialization library, required in some scenarios when using generics. |
| [`Blazor.LocalStorage.WebAssembly`](https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.LocalStorage.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly) | Blazor WebAssembly class library exposing DI-ready `IStorage` type for the `localStorage` implementation (relies on `IJSInProcessRuntime`). |
| [`Blazor.LocalStorage.Server`](https://www.nuget.org/packages/Blazor.LocalStorage.Server) | [![NuGet](https://img.shields.io/nuget/v/Blazor.LocalStorage.Server.svg?style=flat)](https://www.nuget.org/packages/Blazor.LocalStorage.Server) | Blazor Server class library exposing DI-ready `IStorage` type for the `localStorage` implementation (relies on `IJSRuntime`) |
| [`Blazor.Geolocation.WebAssembly`](https://www.nuget.org/packages/Blazor.Geolocation.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.Geolocation.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.Geolocation.WebAssembly) | Razor class library exposing DI-ready `IGeolocation` type (and dependent callback types) for the `geolocation` implementation (relies on `IJSInProcessRuntime`). |
| [`Blazor.Geolocation.Server`](https://www.nuget.org/packages/Blazor.Geolocation.Server) | [![NuGet](https://img.shields.io/nuget/v/Blazor.Geolocation.Server.svg?style=flat)](https://www.nuget.org/packages/Blazor.Geolocation.Server) | Razor class library exposing DI-ready `IGeolocation` type (and dependent callback types) for the `geolocation` implementation (relies on `IJSRuntime`). |
| [`Blazor.LocalStorage.WebAssembly`](https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.LocalStorage.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly) | Blazor WebAssembly class library exposing DI-ready `IStorageService` type for the `localStorage` implementation (relies on `IJSInProcessRuntime`). |
| [`Blazor.LocalStorage.Server`](https://www.nuget.org/packages/Blazor.LocalStorage.Server) | [![NuGet](https://img.shields.io/nuget/v/Blazor.LocalStorage.Server.svg?style=flat)](https://www.nuget.org/packages/Blazor.LocalStorage.Server) | Blazor Server class library exposing DI-ready `IStorageService` type for the `localStorage` implementation (relies on `IJSRuntime`) |
| [`Blazor.SessionStorage.WebAssembly`](https://www.nuget.org/packages/Blazor.SessionStorage.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.SessionStorage.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.SessionStorage.WebAssembly) | Blazor WebAssembly class library exposing DI-ready `IStorageService` type for the `sessionStorage` implementation (relies on `IJSInProcessRuntime`). |
| [`Blazor.SessionStorage.Server`](https://www.nuget.org/packages/Blazor.SessionStorage.Server) | [![NuGet](https://img.shields.io/nuget/v/Blazor.SessionStorage.Server.svg?style=flat)](https://www.nuget.org/packages/Blazor.SessionStorage.Server) | Blazor Server class library exposing DI-ready `IStorageService` type for the `sessionStorage` implementation (relies on `IJSRuntime`) |
| [`Blazor.Geolocation.WebAssembly`](https://www.nuget.org/packages/Blazor.Geolocation.WebAssembly) | [![NuGet](https://img.shields.io/nuget/v/Blazor.Geolocation.WebAssembly.svg?style=flat)](https://www.nuget.org/packages/Blazor.Geolocation.WebAssembly) | Razor class library exposing DI-ready `IGeolocationService` type (and dependent callback types) for the `geolocation` implementation (relies on `IJSInProcessRuntime`). |
| [`Blazor.Geolocation.Server`](https://www.nuget.org/packages/Blazor.Geolocation.Server) | [![NuGet](https://img.shields.io/nuget/v/Blazor.Geolocation.Server.svg?style=flat)](https://www.nuget.org/packages/Blazor.Geolocation.Server) | Razor class library exposing DI-ready `IGeolocationService` type (and dependent callback types) for the `geolocation` implementation (relies on `IJSRuntime`). |

## Using the `Blazor.SourceGenerators` package 📦

As an example, the official [`Blazor.LocalStorage.WebAssembly`](https://www.nuget.org/packages/Blazor.LocalStorage.WebAssembly) package consumes the [`Blazor.SourceGenerators`](https://www.nuget.org/packages/Blazor.SourceGenerators) package. It exposes extension methods specific to Blazor WebAssembly and the [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) Web API.

Consider the _SynchronousLocalStorageExtensions.cs_ C# file:
Consider the IStorageService.cs_ C# file:

```csharp
// Copyright (c) David Pine. All rights reserved.
Expand All @@ -43,9 +45,7 @@ namespace Microsoft.JSInterop;
"getItem",
"setItem:value"
})]
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public partial interface IStorageService
#pragma warning restore CS1591 // The XML comments are source generated
{
}
```
Expand All @@ -60,7 +60,7 @@ This code designates itself into the `Microsoft.JSInterop` namespace, making the
> The generic method descriptors syntax is:
> `"methodName"` for generic return type and `"methodName:parameterName"` for generic parameter type.
The file needs to define an interface and it needs to be `partial`, for example; `public partial interface`. Decorating the class with the `JSAutoInterop` (or `JSAutoGenericInterop) attribute will source generate the following C# code, as shown in the source generated `IStorageService.g.cs`:
The file needs to define an interface and it needs to be `partial`, for example; `public partial interface`. Decorating the class with the `JSAutoInterop` (or `JSAutoGenericInterop) attribute will source generate the following C# code, as shown in the source generated `IStorageServiceService.g.cs`:

```csharp
using Blazor.Serialization.Extensions;
Expand All @@ -72,7 +72,7 @@ namespace Microsoft.JSInterop;
/// <summary>
/// Source generated interface definition of the <c>Storage</c> type.
/// </summary>
public partial interface IStorageService
public partial interface IStorageServiceService
{
/// <summary>
/// Source generated implementation of <c>window.localStorage.length</c>.
Expand Down Expand Up @@ -119,7 +119,7 @@ These internal extension methods rely on the `IJSInProcessRuntime` to perform Ja

- `IStorageService.g.cs`: The interface for the corresponding `Storage` Web API surface area.
- `LocalStorgeService.g.cs`: The `internal` implementation of the `IStorageService` interface.
- `LocalStorageServiceCollectionExtensions.g.cs`: Extension methods to add the `IStorage` service to the dependency injection `IServiceCollection`.
- `LocalStorageServiceCollectionExtensions.g.cs`: Extension methods to add the `IStorageService` service to the dependency injection `IServiceCollection`.

Here is the source generated `LocalStorageService` implementation:

Expand Down Expand Up @@ -202,17 +202,17 @@ namespace Microsoft.Extensions.DependencyInjection;
public static class LocalStorageServiceCollectionExtensions
{
/// <summary>
/// Adds the <see cref="IStorage" /> service to the service collection.
/// Adds the <see cref="IStorageService" /> service to the service collection.
/// </summary>
public static IServiceCollection AddLocalStorageServices(
this IServiceCollection services) =>
services.AddSingleton<IJSInProcessRuntime>(serviceProvider =>
(IJSInProcessRuntime)serviceProvider.GetRequiredService<IJSRuntime>())
.AddSingleton<IStorage, LocalStorage>();
.AddSingleton<IStorageService, LocalStorageService>();
}
```

Putting this all together, the `Blazor.LocalStorage.WebAssembly` NuGet package is actually only 20 lines of code, and it generates full DI-ready services with JavaScript interop.
Putting this all together, the `Blazor.LocalStorage.WebAssembly` NuGet package is actually less than 15 lines of code, and it generates full DI-ready services with JavaScript interop.

The `Blazor.LocalStorage.Server` package, generates extensions on the `IJSRuntime` type.

Expand All @@ -228,9 +228,7 @@ namespace Microsoft.JSInterop;
HostingModel = BlazorHostingModel.Server,
OnlyGeneratePureJS = true,
Url = "https://developer.mozilla.org/docs/Web/API/Window/localStorage")]
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public partial interface IStorageService
#pragma warning restore CS1591 // The XML comments are source generated
public partial interface IStorageServiceService
{
}
```
Expand All @@ -248,7 +246,7 @@ using System.Threading.Tasks;
#nullable enable
namespace Microsoft.JSInterop;

public partial interface IStorageService
public partial interface IStorageServiceService
{
/// <summary>
/// Source generated implementation of <c>window.localStorage.length</c>.
Expand Down Expand Up @@ -339,9 +337,7 @@ namespace Microsoft.JSInterop;
TypeName = "Geolocation",
Implementation = "window.navigator.geolocation",
Url = "https://developer.mozilla.org/docs/Web/API/Geolocation")]
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public partial interface IGeolocationService
#pragma warning restore CS1591 // The XML comments are source generated
{
}
```
Expand Down
14 changes: 14 additions & 0 deletions blazorators.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Geolocation.WebAssem
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Geolocation.Server", "src\Blazor.Geolocation.Server\Blazor.Geolocation.Server.csproj", "{A9F3FE17-EF4C-44B8-B265-7D7DBAA42F84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.SessionStorage.WebAssembly", "src\Blazor.SessionStorage.WebAssembly\Blazor.SessionStorage.WebAssembly.csproj", "{B8FF9EFA-D8DA-43AB-8056-991FFDB609D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.SessionStorage.Server", "src\Blazor.SessionStorage.Server\Blazor.SessionStorage.Server.csproj", "{F54C9271-5C28-498D-9081-59EAA22FEC69}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -74,6 +78,14 @@ Global
{A9F3FE17-EF4C-44B8-B265-7D7DBAA42F84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9F3FE17-EF4C-44B8-B265-7D7DBAA42F84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9F3FE17-EF4C-44B8-B265-7D7DBAA42F84}.Release|Any CPU.Build.0 = Release|Any CPU
{B8FF9EFA-D8DA-43AB-8056-991FFDB609D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8FF9EFA-D8DA-43AB-8056-991FFDB609D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8FF9EFA-D8DA-43AB-8056-991FFDB609D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8FF9EFA-D8DA-43AB-8056-991FFDB609D8}.Release|Any CPU.Build.0 = Release|Any CPU
{F54C9271-5C28-498D-9081-59EAA22FEC69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F54C9271-5C28-498D-9081-59EAA22FEC69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F54C9271-5C28-498D-9081-59EAA22FEC69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F54C9271-5C28-498D-9081-59EAA22FEC69}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -87,6 +99,8 @@ Global
{5E4658A7-4751-4F85-A558-12B8EBCA2BCA} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
{0BAC9703-45EE-4E9E-A0F0-556F02FCB901} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
{A9F3FE17-EF4C-44B8-B265-7D7DBAA42F84} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
{B8FF9EFA-D8DA-43AB-8056-991FFDB609D8} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
{F54C9271-5C28-498D-9081-59EAA22FEC69} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3F86284A-32D2-4F79-B23C-7A0CB8775971}
Expand Down
2 changes: 0 additions & 2 deletions src/Blazor.Geolocation.Server/IGeolocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Microsoft.JSInterop;
Implementation = "window.navigator.geolocation",
HostingModel = BlazorHostingModel.Server,
Url = "https://developer.mozilla.org/docs/Web/API/Geolocation")]
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public partial interface IGeolocationService
#pragma warning restore CS1591 // The XML comments are source generated
{
}
2 changes: 0 additions & 2 deletions src/Blazor.Geolocation.WebAssembly/IGeolocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace Microsoft.JSInterop;
TypeName = "Geolocation",
Implementation = "window.navigator.geolocation",
Url = "https://developer.mozilla.org/docs/Web/API/Geolocation")]
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public partial interface IGeolocationService
#pragma warning restore CS1591 // The XML comments are source generated
{
}
2 changes: 0 additions & 2 deletions src/Blazor.LocalStorage.Server/IStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace Microsoft.JSInterop;
HostingModel = BlazorHostingModel.Server,
OnlyGeneratePureJS = true,
Url = "https://developer.mozilla.org/docs/Web/API/Window/localStorage")]
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public partial interface IStorageService
#pragma warning restore CS1591 // The XML comments are source generated
{
}
2 changes: 0 additions & 2 deletions src/Blazor.LocalStorage.WebAssembly/IStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace Microsoft.JSInterop;
"getItem",
"setItem:value"
})]
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public partial interface IStorageService
#pragma warning restore CS1591 // The XML comments are source generated
{
}
Loading

0 comments on commit 5d57c46

Please sign in to comment.