Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MithrilMan committed Jun 21, 2024
1 parent 2e7aca8 commit 8e74634
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/docs-placeholder.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/example-projects/mithril-shards-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class ExampleClientPeerBinding

ExampleClientPeerBinding class has an EndPoint property that represents the endpoint (IP:Address) of a remote node we'd like to connect to and it's decorated with attributes that are used to validate the configuration during the initialization of the forge.

Validation of the settings make use of [System.ComponentModel.DataAnnotations](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations?view=net-5.0){:target="_blank"} and [RequiredAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.requiredattribute?view=net-5.0){:target="_blank"} used in the example is one of those attribute that belongs to standard set.
Validation of the settings make use of [System.ComponentModel.DataAnnotations](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations?view=net-8.0){:target="_blank"} and [RequiredAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.requiredattribute?view=net-8.0){:target="_blank"} used in the example is one of those attribute that belongs to standard set.
A different story is [IPEndPointValidator]:

```c#
Expand Down
2 changes: 1 addition & 1 deletion docs/mithril-shards/forge-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Mithril Shards implementation, ForgeBuilder class

ForgeBuilder class represents the entry point of a Mithril Shards application, it allows to add a shard by calling the generic `AddShard` method, with different overloads that accept an optional strongly typed shard setting file with an optional setting file validator.

By using `ConfigureLogging` it's possible to configure logging, it's basically a wrapper on the inner [HostBuilder ConfigureLogging](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilder.configurelogging?view=aspnetcore-1.1&viewFallbackFrom=aspnetcore-5.0){:target="_blank"} method, you could use it to have a finer control over logging configuration and available providers, but the easier way to log is by using the available [SerilogShard] that uses Serilog to configure the logging and relies on a configurable setting file where you can specify which sink to use.
By using `ConfigureLogging` it's possible to configure logging, it's basically a wrapper on the inner [HostBuilder ConfigureLogging](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilder.configurelogging?view=aspnetcore-1.1&viewFallbackFrom=aspnetcore-8.0){:target="_blank"} method, you could use it to have a finer control over logging configuration and available providers, but the easier way to log is by using the available [SerilogShard] that uses Serilog to configure the logging and relies on a configurable setting file where you can specify which sink to use.
You can find more details on its specific documentation page and an example of its usage in the [example project]

After declaring an instance we have to specify which implementation of Forge we want to use.
Expand Down
2 changes: 1 addition & 1 deletion docs/mithril-shards/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Pretending to be into a Tolkien universe, I thought of defining features as *sha

To find analogies with .net naming conventions:

- **Forge** (to be more precise, **ForgeBuilder**) is a [HostBuilder](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.hostbuilder?view=dotnet-plat-ext-5.0){:target="_blank"} on steroids (actually it encapsulate a HostBuilder instance).
- **Forge** (to be more precise, **ForgeBuilder**) is a [HostBuilder](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.hostbuilder?view=net-8.0){:target="_blank"} on steroids (actually it encapsulate a HostBuilder instance).
- **Shard** is an application part that gets merged into the hostbuilder, using dependency injection, extending its functionality
- **Artifact** is just an allegoric view of the result of `forgeBuilderInstance.RunConsoleAsync()`.

Expand Down
2 changes: 1 addition & 1 deletion docs/shards/bitcoin/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Before being able to handshake, whenever a connection has been established betwe

## Peer Context

Default Mithril Shards implementation uses `PeerContext` class to store, among other things, information like peer unique identification, direction (inbound/outbound) remote and local endpoints, user agent identification, negotiated protocol version and other attachable properties leveraging the .Net [IFeatureCollection](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.features.ifeaturecollection?view=aspnetcore-5.0){:target="_blank"} interface.
Default Mithril Shards implementation uses `PeerContext` class to store, among other things, information like peer unique identification, direction (inbound/outbound) remote and local endpoints, user agent identification, negotiated protocol version and other attachable properties leveraging the .Net [IFeatureCollection](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.features.ifeaturecollection?view=aspnetcore-8.0){:target="_blank"} interface.

Bitcoin needs some additional information and some of the properties that are ubiquitous needed among all optional Bitcoin features (shards) like wallet, APIs, indexer, etc... have been defined directly into `BitcoinPeerContext` that extends the default `PeerContext`. Some of the additional properties are Permissions (that may change the FN behavior based on its set) and TimeOffset, that's an important aspect for the consensus logic.

Expand Down
8 changes: 4 additions & 4 deletions docs/shards/web-api/creating-a-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ExampleController : MithrilControllerBase

### Define the area

Line 1 describes, using [AreaAttribute](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.areaattribute?view=aspnetcore-5.0){:target="_blank"}, the area we want this controller to be included.
Line 1 describes, using [AreaAttribute](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.areaattribute?view=aspnetcore-8.0){:target="_blank"}, the area we want this controller to be included.
WebApiArea is an helper class that just contains a bounch of constant string of known areas: "api" and "dev".

Expand Down Expand Up @@ -92,7 +92,7 @@ Lines 13-18 declare and implement an action.
In this case, the action is declared as `HttpGet`, this mean that it will only respond to GET requests. If you try to access that action with others HTTP verbs, it will return a status error `405 Method Not Allowed`

`[ProducesResponseType(StatusCodes.Status200OK)]` declare known action status that can be returned by the action.
It's just an helpful attribute useful to produce a better documentation on swagger interface and document definition but the action itself may even generate different statuses. This documentation however don't cover canonical Web API implementation, so [refer to .Net documentation](https://docs.microsoft.com/it-it/aspnet/core/web-api/advanced/conventions?view=aspnetcore-5.0){:target="_blank"}. to read more about it.
It's just an helpful attribute useful to produce a better documentation on swagger interface and document definition but the action itself may even generate different statuses. This documentation however don't cover canonical Web API implementation, so [refer to .Net documentation](https://learn.microsoft.com/en-us/aspnet/core/web-api/advanced/conventions?view=aspnetcore-8.0){:target="_blank"}. to read more about it.

To return an action result, the method `Ok` is invoked, passing the payload (that will be serialized in JSON) as a response.

Expand Down Expand Up @@ -132,12 +132,12 @@ public IActionResult Connect(PeerManagementConnectRequest request)
In this example, this action will return 404 (not found) if the member variables _requiredConnection isn't set, or 400 (bad request) if the input peer isn't formatted properly as a valid endpoint. If everything goes fine it will instead return 200 (ok).

!!! tip
In case of action problems, instead of calling BadRequest or Problem method extensions, use `ValidationProblem`, it uses a ValidationProblemDetails response that's consistent with automatic validation error responses, [as stated here](https://docs.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-5.0#default-badrequest-response){:target="_blank"}.
In case of action problems, instead of calling BadRequest or Problem method extensions, use `ValidationProblem`, it uses a ValidationProblemDetails response that's consistent with automatic validation error responses, [as stated here](https://docs.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-8.0#default-badrequest-response){:target="_blank"}.
In the example above, NotFound could be replaced with ValidationProblem too for a consistent behavior.

### Producing documentation for Swagger UI

In order to produce proper documentation to be shown on Swagger UI, [XML comments within C#](https://docs.microsoft.com/it-it/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-5.0&tabs=visual-studio#xml-comments){:target="_blank"} source can be used but the build process has to generate a documentation file.
In order to produce proper documentation to be shown on Swagger UI, [XML comments within C#](https://docs.microsoft.com/it-it/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-8.0&tabs=visual-studio#xml-comments){:target="_blank"} source can be used but the build process has to generate a documentation file.

The easier way is to edit your project file adding this snippet:

Expand Down
6 changes: 3 additions & 3 deletions docs/shards/web-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Mithril Shards, WebApiShard Overview

WebApiShard is an important shard that allows to expose Web API endpoints based on [OpeAPI specifications](https://swagger.io/specification/){:target="_blank"}.

[Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore){:target="_blank"} is used under the hood and you can find more technical information about OpenAPI, REST APIs and Swagger concepts on [microsoft documentation](https://docs.microsoft.com/it-it/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetcore-5.0){:target="_blank"}.
[Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore){:target="_blank"} is used under the hood and you can find more technical information about OpenAPI, REST APIs and Swagger concepts on [microsoft documentation](https://learn.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetcore-8.0){:target="_blank"}.

WebApiShard comes with a [WebApiSettings] class that holds settings to configure the service.

Expand All @@ -16,7 +16,7 @@ To add the shard to the forge, the `IForgeBuilder` extension `UseApi` has to be
public static IForgeBuilder UseApi(this IForgeBuilder forgeBuilder, Action<WebApiOptions>? options = null)
```

WebApiShard implements the Web API controllers using the standard aspnet [ControllerBase](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase?view=aspnetcore-5.0){:target="_blank"} class but decorates it with a set of default attributes needed to expose these controllers in the right context.
WebApiShard implements the Web API controllers using the standard aspnet [ControllerBase](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase?view=aspnetcore-8.0){:target="_blank"} class but decorates it with a set of default attributes needed to expose these controllers in the right context.
To create a proper WebApiShard controller, an abstract base class `MithrilControllerBase` exists that applies already the required attributes.

```c#
Expand Down Expand Up @@ -55,7 +55,7 @@ public abstract class WebApiArea
!!! note
WebApiShard controllers have to belong to a specific area. More information in [Creating a Controller] section.

`DisableByEndPointActionFilterAttribute` class, that's a registered [ActionFilterAttribute](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.filters.actionfilterattribute?view=aspnetcore-5.0){:target="_blank"}, is responsible to enforce proper checks against executing an action on an unspecified, unknown or disabled area.
`DisableByEndPointActionFilterAttribute` class, that's a registered [ActionFilterAttribute](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.filters.actionfilterattribute?view=aspnetcore-8.0){:target="_blank"}, is responsible to enforce proper checks against executing an action on an unspecified, unknown or disabled area.

!!! warning
The current implementation may be subject to changes to implement the authentication and authorization layer.
2 changes: 1 addition & 1 deletion docs/shards/web-api/using-webapishard.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static IForgeBuilder UseApi(this IForgeBuilder forgeBuilder, Action<WebAp

WebApiOptions class allows to customize the discovery process that's responsible to find and register Web API controllers end include them into a specific [ApiServiceDefinition](#apiservicedefinition).

The discovery process happens during WebApiShard initialization: it generates an [ApplicationPart](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.applicationparts.applicationpart?view=aspnetcore-5.0){:target="blank"} for each registered shard that will include all discovered `MithrilControllerBase`(ControllerBase) types defined in the shard assembly.
The discovery process happens during WebApiShard initialization: it generates an [ApplicationPart](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.applicationparts.applicationpart?view=aspnetcore-8.0){:target="blank"} for each registered shard that will include all discovered `MithrilControllerBase`(ControllerBase) types defined in the shard assembly.

### ControllersSeeker

Expand Down

0 comments on commit 8e74634

Please sign in to comment.