Skip to content

Commit

Permalink
new mechanism to disable automatic Wolverine module discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed May 20, 2024
1 parent 88341c1 commit 065856a
Show file tree
Hide file tree
Showing 86 changed files with 622 additions and 563 deletions.
8 changes: 4 additions & 4 deletions docs/guide/codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Lastly, you have a couple options about how Wolverine handles the dynamic code g
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
// The default behavior. Dynamically generate the
// types on the first usage
// The default behavior. Dynamically generate the
// types on the first usage
opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Dynamic;

// Never generate types at runtime, but instead try to locate
Expand All @@ -53,7 +53,7 @@ using var host = await Host.CreateDefaultBuilder()

// Hybrid approach that first tries to locate the types
// from the application assembly, but falls back to
// generating the code and dynamic type. Also writes the
// generating the code and dynamic type. Also writes the
// generated source code file to disk
opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto;
}).StartAsync();
Expand Down Expand Up @@ -127,7 +127,7 @@ using var host = await Host.CreateDefaultBuilder()
if (context.HostingEnvironment.IsProduction())
{
opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Static;

// You probably only ever want to do this in Production
opts.Services.AssertAllExpectedPreBuiltTypesExistOnStartUp();
}
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ return await Host.CreateDefaultBuilder(args)
.AddSource("Wolverine");
});
})

// Executing with Oakton as the command line parser to unlock
// quite a few utilities and diagnostics in our Wolverine application
.RunOaktonCommands(args);
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ using var host = await Host.CreateDefaultBuilder()
{
// Surely plenty of other configuration for Wolverine...
// This *temporary* line of code will write out a full report about why or
// This *temporary* line of code will write out a full report about why or
// why not Wolverine is finding this handler and its candidate handler messages
Console.WriteLine(opts.DescribeHandlerMatch(typeof(MyMissingMessageHandler)));
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Samples/DocumentationSamples/HandlerDiscoverySamples.cs#L156-L168' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_describe_handler_match' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Samples/DocumentationSamples/HandlerDiscoverySamples.cs#L148-L160' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_describe_handler_match' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Asserting Wolverine Configuration
Expand Down Expand Up @@ -180,6 +180,6 @@ public static void using_preview_subscriptions(IMessageBus bus)
}
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Runtime/Routing/routing_precedence.cs#L76-L90' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_preview_subscriptions' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Testing/CoreTests/Runtime/Routing/routing_precedence.cs#L70-L84' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_preview_subscriptions' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

6 changes: 3 additions & 3 deletions docs/guide/durability/dead-letter-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ To integrate the Dead Letters REST API into your WolverineFX application, you si
<a id='snippet-sample_register_dead_letter_endpoints'></a>
```cs
app.MapDeadLettersEndpoints()

// It's a Minimal API endpoint group,
// so you can add whatever authorization
// or OpenAPI metadata configuration you need
// for just these endpoints
//.RequireAuthorization("Admin")
;
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Http/WolverineWebApi/Program.cs#L127-L137' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_register_dead_letter_endpoints' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Http/WolverineWebApi/Program.cs#L126-L136' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_register_dead_letter_endpoints' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Using the Dead Letters REST API
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/durability/efcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ builder.Host.UseWolverine(opts =>
// Set up Entity Framework Core as the support
// for Wolverine's transactional middleware
opts.UseEntityFrameworkCoreTransactions();

// Enrolling all local queues into the
// durable inbox/outbox processing
opts.Policies.UseDurableLocalQueues();
Expand Down Expand Up @@ -201,7 +201,7 @@ public class SampleMappedDbContext : DbContext
}
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/PersistenceTests/SampleDbContext.cs#L57-L83' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_mapping_envelope_storage_to_dbcontext-1' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/PersistenceTests/SampleDbContext.cs#L56-L82' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_mapping_envelope_storage_to_dbcontext-1' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down Expand Up @@ -274,7 +274,7 @@ public async Task Post3(
// Gotta attach the DbContext to the outbox
// BEFORE sending any messages
outbox.Enroll(dbContext);

// Publish a message to take action on the new item
// in a background thread
await outbox.PublishAsync(new ItemCreated
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/durability/idempotency.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ using var host = await Host.CreateDefaultBuilder()
opts.Durability.KeepAfterMessageHandling = 10.Minutes();
}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/PersistenceTests/Samples/DocumentationSamples.cs#L194-L205' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configuring_keepaftermessagehandling' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/PersistenceTests/Samples/DocumentationSamples.cs#L193-L204' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configuring_keepaftermessagehandling' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
20 changes: 10 additions & 10 deletions docs/guide/durability/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Consider this sample message handler from Wolverine's [AppWithMiddleware sample
<!-- snippet: sample_DebitAccountHandler_that_uses_IMessageContext -->
<a id='snippet-sample_debitaccounthandler_that_uses_imessagecontext'></a>
```cs
[Transactional]
[Transactional]
public static async Task Handle(
DebitAccount command,
Account account,
IDocumentSession session,
DebitAccount command,
Account account,
IDocumentSession session,
IMessageContext messaging)
{
account.Balance -= command.Amount;

// This just marks the account as changed, but
// doesn't actually commit changes to the database
// yet. That actually matters as I hopefully explain
Expand All @@ -40,12 +40,12 @@ public static async Task Handle(
else if (account.Balance < 0)
{
await messaging.SendAsync(new AccountOverdrawn(account.Id), new DeliveryOptions{DeliverWithin = 1.Hours()});

// Give the customer 10 days to deal with the overdrawn account
await messaging.ScheduleAsync(new EnforceAccountOverdrawnDeadline(account.Id), 10.Days());
}
// "messaging" is a Wolverine IMessageContext or IMessageBus service

// "messaging" is a Wolverine IMessageContext or IMessageBus service
// Do the deliver within rule on individual messages
await messaging.SendAsync(new AccountUpdated(account.Id, account.Balance),
new DeliveryOptions { DeliverWithin = 5.Seconds() });
Expand Down Expand Up @@ -153,7 +153,7 @@ using var host = await Host.CreateDefaultBuilder()
.UseDurableInbox();

// Make every single listener endpoint use
// durable message storage
// durable message storage
opts.Policies.UseDurableInboxOnAllListeners();
}).StartAsync();
```
Expand Down Expand Up @@ -270,7 +270,7 @@ var app = builder.Build();
// the message storage
return await app.RunOaktonCommands(args);
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/PersistenceTests/Samples/DocumentationSamples.cs#L163-L189' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_setup_postgresql_storage' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/PersistenceTests/Samples/DocumentationSamples.cs#L162-L188' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_setup_postgresql_storage' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Database Schema Objects
Expand Down
9 changes: 4 additions & 5 deletions docs/guide/durability/leadership-and-troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,22 @@ using var host = await Host.CreateDefaultBuilder()
{
opts.Services.AddMarten("some connection string")

// This adds quite a bit of middleware for
// This adds quite a bit of middleware for
// Marten
.IntegrateWithWolverine();

// You want this maybe!
opts.Policies.AutoApplyTransactions();

if (context.HostingEnvironment.IsDevelopment())
{
// But wait! Optimize Wolverine for usage as
// But wait! Optimize Wolverine for usage as
// if there would never be more than one node running
opts.Durability.Mode = DurabilityMode.Solo;
}

}).StartAsync();
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Samples/DocumentationSamples/DurabilityModes.cs#L65-L89' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configuring_the_solo_mode' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Samples/DocumentationSamples/DurabilityModes.cs#L63-L86' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_configuring_the_solo_mode' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Running your Wolverine application like this means that Wolverine is able to more quickly start the transactional inbox
Expand Down
12 changes: 6 additions & 6 deletions docs/guide/durability/marten/event-forwarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ builder.Host.UseWolverine(opts =>
// to the database happen
opts.Policies.OnException<NpgsqlException>()
.RetryWithCooldown(50.Milliseconds(), 100.Milliseconds(), 250.Milliseconds());
// Automatic usage of transactional middleware as

// Automatic usage of transactional middleware as
// Wolverine recognizes that an HTTP endpoint or message handler
// persists data
opts.Policies.AutoApplyTransactions();
Expand All @@ -120,7 +120,7 @@ public static Task<ITrackedSession> SaveInMartenAndWaitForOutgoingMessagesAsync(
var session = factory.OpenSession(context);
action(session);
await session.SaveChangesAsync();

// Shouldn't be necessary, but real life says do it anyway
await context.As<MessageContext>().FlushOutgoingMessagesAsync();
}, timeoutInMilliseconds);
Expand All @@ -144,7 +144,7 @@ public async Task execution_of_forwarded_events_can_be_awaited_from_tests()
services.AddMarten(Servers.PostgresConnectionString)
.IntegrateWithWolverine().EventForwardingToWolverine(opts =>
{
opts.SubscribeToEvent<SecondEvent>().TransformedTo(e =>
opts.SubscribeToEvent<SecondEvent>().TransformedTo(e =>
new SecondMessage(e.StreamId, e.Sequence));
});
}).StartAsync();
Expand All @@ -154,7 +154,7 @@ public async Task execution_of_forwarded_events_can_be_awaited_from_tests()
{
session.Events.Append(aggregateId, new SecondEvent());
}, 100_000);

using var store = host.Services.GetRequiredService<IDocumentStore>();
await using var session = store.LightweightSession();
var events = await session.Events.FetchStreamAsync(aggregateId);
Expand All @@ -178,5 +178,5 @@ public static Task HandleAsync(SecondMessage message, IDocumentSession session)
return session.SaveChangesAsync();
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/MartenTests/event_streaming.cs#L222-L228' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_execution_of_forwarded_events_second_message_to_fourth_event' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/MartenTests/event_streaming.cs#L217-L223' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_execution_of_forwarded_events_second_message_to_fourth_event' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
10 changes: 5 additions & 5 deletions docs/guide/durability/marten/event-sourcing.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task Post(
{
// This is important!
outbox.Enroll(session);

// Fetch the current value of the Order aggregate
var stream = await session
.Events
Expand Down Expand Up @@ -179,7 +179,7 @@ public static IEnumerable<object> Handle(MarkItemReady command, Order order)
}
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/OrderEventSourcingSample/Order.cs#L252-L279' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_markitemreadyhandler' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/OrderEventSourcingSample/Order.cs#L251-L278' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_markitemreadyhandler' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

In the case above, Wolverine is wrapping middleware around our basic command handler to
Expand Down Expand Up @@ -293,14 +293,14 @@ Here's an alternative to the `MarkItemReady` handler that uses `Events`:
[AggregateHandler]
public static async Task<(Events, OutgoingMessages)> HandleAsync(MarkItemReady command, Order order, ISomeService service)
{
// All contrived, let's say we need to call some
// All contrived, let's say we need to call some
// kind of service to get data so this handler has to be
// async
var data = await service.FindDataAsync();

var messages = new OutgoingMessages();
var events = new Events();

if (order.Items.TryGetValue(command.ItemName, out var item))
{
// Not doing this in a purist way here, but just
Expand Down Expand Up @@ -328,7 +328,7 @@ public static async Task<(Events, OutgoingMessages)> HandleAsync(MarkItemReady c
return (events, messages);
}
```
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/OrderEventSourcingSample/Order.cs#L293-L333' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_events_and_messages_from_aggregatehandler' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Persistence/OrderEventSourcingSample/Order.cs#L290-L330' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_events_and_messages_from_aggregatehandler' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
9 changes: 4 additions & 5 deletions docs/guide/durability/marten/inbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ builder.Services.AddMarten(opts =>
builder.Host.UseWolverine(opts =>
{
opts.Policies.OnAnyException().RetryWithCooldown(50.Milliseconds(), 100.Milliseconds(), 250.Milliseconds());

opts.Services.AddScoped<IMessageRecordRepository, MartenMessageRecordRepository>();

opts.Policies.DisableConventionalLocalRouting();
opts.UseRabbitMq().AutoProvision();

opts.Policies.UseDurableInboxOnAllListeners();
opts.Policies.UseDurableOutboxOnAllSendingEndpoints();

opts.ListenToRabbitQueue("chaos2");
opts.PublishAllMessages().ToRabbitQueue("chaos2");



opts.Policies.AutoApplyTransactions();
});
```
Expand Down
9 changes: 4 additions & 5 deletions docs/guide/durability/marten/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ builder.Services.AddMarten(opts =>
builder.Host.UseWolverine(opts =>
{
opts.Policies.OnAnyException().RetryWithCooldown(50.Milliseconds(), 100.Milliseconds(), 250.Milliseconds());

opts.Services.AddScoped<IMessageRecordRepository, MartenMessageRecordRepository>();

opts.Policies.DisableConventionalLocalRouting();
opts.UseRabbitMq().AutoProvision();

opts.Policies.UseDurableInboxOnAllListeners();
opts.Policies.UseDurableOutboxOnAllSendingEndpoints();

opts.ListenToRabbitQueue("chaos2");
opts.PublishAllMessages().ToRabbitQueue("chaos2");



opts.Policies.AutoApplyTransactions();
});
```
Expand Down
Loading

0 comments on commit 065856a

Please sign in to comment.