generated from mauroservienti/code-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from mauroservienti/generic-host-support-1.1
Generic host support - v1.1
- Loading branch information
Showing
33 changed files
with
604 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
using NServiceBus; | ||
using Microsoft.Extensions.Hosting; | ||
using NServiceBus; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Serilog; | ||
|
||
namespace MyService | ||
{ | ||
class Program | ||
public class Program | ||
{ | ||
static async Task Main(string[] args) | ||
public static void Main(string[] args) | ||
{ | ||
Console.Title = typeof(Program).Namespace; | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args, Action<EndpointConfiguration> configPreview = null) | ||
{ | ||
var builder = Host.CreateDefaultBuilder(args); | ||
builder.UseConsoleLifetime(); | ||
|
||
builder.UseSerilog((context, services, loggerConfiguration) => loggerConfiguration | ||
.ReadFrom.Configuration(context.Configuration) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console()); | ||
|
||
var endpointConfiguration = new MyServiceConfiguration(); | ||
var endpointInstance = await Endpoint.Start(endpointConfiguration); | ||
builder.UseNServiceBus(ctx => | ||
{ | ||
var config = new MyServiceConfiguration(); | ||
configPreview?.Invoke(config); | ||
Console.WriteLine($"{typeof(Program).Namespace} started. Press any key to stop."); | ||
Console.ReadLine(); | ||
return config; | ||
}); | ||
|
||
await endpointInstance.Stop(); | ||
return builder; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...rationTesting.Tests.TestEndpoint/NServiceBus.IntegrationTesting.Tests.TestEndpoint.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NServiceBus" Version="7.4.4" /> | ||
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="1.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MyMessages\MyMessages.csproj" /> | ||
<ProjectReference Include="..\NServiceBus.AssemblyScanner.Extensions\NServiceBus.AssemblyScanner.Extensions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
30 changes: 30 additions & 0 deletions
30
src/NServiceBus.IntegrationTesting.Tests.TestEndpoint/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace NServiceBus.IntegrationTesting.Tests.TestEndpoint | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) | ||
{ | ||
var builder = Host.CreateDefaultBuilder(args); | ||
builder.UseConsoleLifetime(); | ||
|
||
builder.UseNServiceBus(ctx => | ||
{ | ||
var config = new EndpointConfiguration("NServiceBus.IntegrationTesting.Tests.TestEndpoint"); | ||
config.UseTransport<LearningTransport>(); | ||
config.AssemblyScanner().ExcludeAssemblies("NServiceBus.IntegrationTesting.Tests.dll"); | ||
return config; | ||
}); | ||
|
||
return builder; | ||
} | ||
} | ||
} |
Oops, something went wrong.