/
Program.cs
60 lines (48 loc) · 1.52 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using NServiceBus;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
ContentRootPath = AppContext.BaseDirectory
});
//next two lines will make NSB fail
var path = System.Reflection.Assembly.GetExecutingAssembly().Location;
System.Reflection.Assembly.LoadFile(path);
var endpointConfiguration = new NServiceBus.EndpointConfiguration("Something");
var transport = endpointConfiguration.UseTransport<LearningTransport>();
EndpointWithExternallyManagedServiceProvider.Create(endpointConfiguration, builder.Services);
builder.Services.AddTransient<MyService>();
builder.Services.AddControllers();
try
{
//prints IOC container
builder.Services.Select(x => x.ServiceType.ToString())
.OrderBy(x => x)
.ToList().ForEach(x => Console.WriteLine(x));
var app = builder.Build();
app.MapControllers();
app.Run();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
public class MyService { }
public class MyMessage : ICommand { }
public class MyMessageHandler : IHandleMessages<MyMessage>
{
private readonly MyService service;
public MyMessageHandler(MyService service)
{
this.service = service;
}
public Task Handle(MyMessage command, IMessageHandlerContext context)
{
return Task.CompletedTask;
}
}