Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 0 additions & 123 deletions docs/guide/migrating-to-wolverine.md
Original file line number Diff line number Diff line change
Expand Up @@ -688,129 +688,6 @@ opts.Policies.RegisterInteropMessageAssembly(typeof(SharedMessages).Assembly);
Wolverine detects message types from standard NServiceBus headers. You may need [message type aliases](/guide/messages#message-type-name-or-alias)
to bridge naming differences. See the full [interoperability guide](/tutorials/interop#interop-with-nservicebus).

### NServiceBus Shim Interfaces

Wolverine provides shim interfaces in the `Wolverine.Shims.NServiceBus` namespace that mimic the core NServiceBus
API surface while delegating to Wolverine's `IMessageBus` and `IMessageContext` under the hood. These shims let
you migrate handler code incrementally without rewriting every handler signature at once.

::: tip
The shim interfaces are included in the core Wolverine NuGet package -- no additional packages are needed.
While these shims ease migration, the Wolverine team recommends eventually moving to Wolverine's native
convention-based handlers and pure function style for the best developer experience.
:::

#### Automatic Handler Discovery

Wolverine automatically discovers classes implementing `IHandleMessages<T>` during its normal
[handler discovery](/guide/handlers/discovery) assembly scanning -- no explicit registration is needed.
The `IMessageHandlerContext` parameter in `Handle(T message, IMessageHandlerContext context)` is
automatically resolved via Wolverine's built-in code generation.

Just make sure the assembly containing your `IHandleMessages<T>` implementations is included in
Wolverine's discovery. By default, Wolverine scans the application assembly and any assemblies
explicitly added via `opts.Discovery.IncludeAssembly()`. See the
[handler discovery documentation](/guide/handlers/discovery) for more details on controlling which
assemblies are scanned.

#### DI Registration for Non-Handler Interfaces

If you need to inject NServiceBus shim interfaces (`IMessageSession`, `IEndpointInstance`,
`IUniformSession`, `ITransactionalSession`) into services outside of message handlers via
constructor injection, register them with:

```csharp
builder.Host.UseWolverine(opts =>
{
opts.UseNServiceBusShims();

// Your Wolverine configuration...
});
```

#### Available Interfaces

| NServiceBus Shim | Delegates To | Purpose |
|-----------------|-------------|---------|
| `IMessageSession` | `IMessageBus` | Send/Publish outside of handlers |
| `IEndpointInstance` | `IMessageBus` + `IHost` | Running endpoint with lifecycle |
| `IMessageHandlerContext` | `IMessageContext` | Send/Publish/Reply inside handlers |
| `IUniformSession` | `IMessageBus` | Unified Send/Publish (inside or outside handlers) |
| `ITransactionalSession` | `IMessageBus` | Transactional Send/Publish (Open/Commit are obsolete) |
| `IHandleMessages<T>` | `IWolverineHandler` | Handler discovery marker |

#### Using IHandleMessages\<T\>

The `IHandleMessages<T>` shim extends `IWolverineHandler`, so implementing it automatically registers your
handler with Wolverine's handler discovery:

```csharp
using Wolverine.Shims.NServiceBus;

// This handler is discovered by Wolverine via the IWolverineHandler marker
public class OrderHandler : IHandleMessages<PlaceOrder>
{
public async Task Handle(PlaceOrder message, IMessageHandlerContext context)
{
// context.Send, context.Publish, context.Reply all delegate to Wolverine
await context.Publish(new OrderPlaced(message.OrderId));
await context.Reply(new PlaceOrderResponse { Success = true });
}
}
```

#### Using IMessageSession / IEndpointInstance

Inject `IMessageSession` or `IEndpointInstance` to send and publish messages outside of handlers:

```csharp
using Wolverine.Shims.NServiceBus;

public class OrderController : ControllerBase
{
private readonly IMessageSession _session;

public OrderController(IMessageSession session) => _session = session;

[HttpPost]
public async Task<IActionResult> PlaceOrder(PlaceOrderRequest request)
{
await _session.Send(new PlaceOrder(request.OrderId));
return Accepted();
}
}
```

#### NServiceBus-Style Options

The shims include `SendOptions`, `PublishOptions`, and `ReplyOptions` classes that map to Wolverine's
`DeliveryOptions`:

```csharp
var options = new SendOptions();
options.SetDestination("remote-endpoint"); // routes to a named endpoint
options.SetHeader("tenant-id", "acme"); // adds a header
options.DelayDeliveryWith(TimeSpan.FromMinutes(5)); // schedules delivery

await session.Send(new PlaceOrder("ABC-123"), options);
```

#### ITransactionalSession

`ITransactionalSession` delegates `Send` and `Publish` to `IMessageBus`. The `Open()` and `Commit()`
lifecycle methods are marked `[Obsolete]` and throw `NotSupportedException` because Wolverine handles
transactional messaging automatically via its built-in [outbox](/guide/durability/):

```csharp
// These methods are obsolete -- just delete the calls
// session.Open(); // throws NotSupportedException
// session.Commit(); // throws NotSupportedException

// Send and Publish work normally
await session.Send(new PlaceOrder("ABC-123"));
await session.Publish(new OrderPlaced("ABC-123"));
```

### Migration Checklist

**Phase 1: Coexistence**
Expand Down
138 changes: 0 additions & 138 deletions src/Testing/CoreTests/Shims/nservicebus_end_to_end.cs

This file was deleted.

Loading
Loading