Skip to content

Commit

Permalink
docs: change source of truth instead of generated file
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexZeitler authored and oskardudycz committed May 13, 2023
1 parent 1f35716 commit 36ad0ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 5 additions & 5 deletions docs/configuration/hostbuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static IServiceCollection AddUserModule(this IServiceCollection services)
return services;
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CoreTests/BootstrappingExamples.cs#L12-L29' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_addusermodule' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CoreTests/BootstrappingExamples.cs#L14-L31' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_addusermodule' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

And next, let's put that into context with its usage inside your application's bootstrapping:
Expand All @@ -228,7 +228,7 @@ using var host = await Host.CreateDefaultBuilder()
services.AddUserModule();
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CoreTests/BootstrappingExamples.cs#L70-L85' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_configure_marten' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CoreTests/BootstrappingExamples.cs#L83-L98' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_configure_marten' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

The `ConfigureMarten()` method is the interesting part of the code samples above. That is registering a small
Expand Down Expand Up @@ -263,7 +263,7 @@ internal class UserMartenConfiguration: IConfigureMarten
}
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CoreTests/BootstrappingExamples.cs#L51-L62' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_usermartenconfiguration' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CoreTests/BootstrappingExamples.cs#L64-L75' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_usermartenconfiguration' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

and registering it in your IoC container something like this:
Expand All @@ -276,7 +276,7 @@ public static IServiceCollection AddUserModule2(this IServiceCollection services
// This applies additional configuration to the main Marten DocumentStore
// that is configured elsewhere
services.AddSingleton<IConfigureMarten, UserMartenConfiguration>();

// If you're using multiple databases per Host, register `IConfigureMarten<T>`, like this:
services.AddSingleton<IConfigureMarten<IInvoicingStore>, InvoicingStoreConfiguration>();

Expand All @@ -286,7 +286,7 @@ public static IServiceCollection AddUserModule2(this IServiceCollection services
return services;
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CoreTests/BootstrappingExamples.cs#L34-L48' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_addusermodule2' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CoreTests/BootstrappingExamples.cs#L36-L53' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_addusermodule2' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Using Lightweight Sessions
Expand Down
15 changes: 14 additions & 1 deletion src/CoreTests/BootstrappingExamples.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Threading.Tasks;
using CoreTests.Examples;
using Marten;
using Marten.Internal;
using Marten.Testing.Documents;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -39,6 +41,9 @@ public static IServiceCollection AddUserModule2(this IServiceCollection services
// that is configured elsewhere
services.AddSingleton<IConfigureMarten, UserMartenConfiguration>();

// If you're using multiple databases per Host, register `IConfigureMarten<T>`, like this:
services.AddSingleton<IConfigureMarten<IInvoicingStore>, InvoicingStoreConfiguration>();

// Other service registrations specific to the User submodule
// within the bigger system

Expand All @@ -48,6 +53,14 @@ public static IServiceCollection AddUserModule2(this IServiceCollection services
#endregion
}

public class InvoicingStoreConfiguration: IConfigureMarten<IInvoicingStore>
{
public void Configure(IServiceProvider services, StoreOptions options)
{
// configure options
}
}

#region sample_UserMartenConfiguration

internal class UserMartenConfiguration: IConfigureMarten
Expand Down Expand Up @@ -85,4 +98,4 @@ public static async Task using_configure_marten()
#endregion

}
}
}

0 comments on commit 36ad0ac

Please sign in to comment.