I have this piece of code working in asp.net core application, now I want to use eventBus in genericHost based application. So, what is the equivalent code?
public static void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
ConfigureEventBus(app);
}
public static void ConfigureEventBus(IApplicationBuilder app)
{
if (app != null)
{
var eventBus = app.ApplicationServices.GetRequiredService<IConsumeEventBus>();
eventBus.Subscribe<DemoEvent, DemoEventHandler>("18Julyexchange", "18Julyqueue", "18JulyRoute");
}
}
My generic host based application code
var host = new HostBuilder()
.ConfigureHostConfiguration(configHost =>
{
configHost.SetBasePath(GetContentRootPath());
configHost.AddJsonFile("AppSettings.json", optional: true);
configHost.AddCommandLine(args);
})
.ConfigureServices((hostContext, services) =>
{
})
.ConfigureLogging((hostContext, configLogging) =>
{
})
.UseConsoleLifetime()
.Build();
Console.WriteLine("Hello World!");
host.RunConsoleAsync();