I have to change Microsoft DI to Ninject have you got idea how use this in startup?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Test.QuartzServiceJobs
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
other code
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
namespace Test.QuartzServiceJobs
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IJobFactory, JobFactory>();
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
services.AddHostedService<QuartzHostedService>();
services.AddSingleton<ImportMapSaveDataForKoreaJob>();
services.AddSingleton(new JobSchedule(
jobType: typeof(ImportMapSaveDataForKoreaJob),
cronExpression: "0/10 * * * * ?")); //every 10 seconds
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
}
and Ninject - from another project
var kernel = new StandardKernel(
new SomeNinjectModule(),
);
IoC.Container = new IoCContainer(kernel);
module Ninject
public class SomeNinjectModule : NinjectModule
{
public override void Load()
{
this.Bind(x => x
.FromAssembliesMatching("Test.*.dll", "*.exe")
.SelectAllClasses()
.BindAllInterfaces()
.Configure(y => y.InTransientScope())
);
}
}