I am using Simple Injector in an ASP.NET 5 app, and need to switch over my Identity
registrations from the built in Microsoft DI.
Currently, it looks like this;
services.AddIdentity<AppUser, AppRole>(o => {
o.Password.RequiredLength = 6;
o.Password.RequireNonLetterOrDigit = false;
o.Password.RequireDigit = true;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
})
.AddUserStore<UserStore<AppUser>>()
.AddRoleStore<RoleStore<AppRole>>()
.AddDefaultTokenProviders();
I'm aware of how to use Container.Register<T>
, but I'm having a hard time finding the equivalent way of registering these particular things in Simple Injector. Has anyone else done this that might be able to help?
I am trying to do this because I need to use property injection; I have a task that will be setup using Quartz.NET
, and it instantiates things on its own, like this -
public class HelloJob : IJob
{
public void Execute(IJobExecutionContext context)
{
Console.WriteLine("Greetings from HelloJob!");
}
}
// define the job and tie it to our HelloJob class
IJobDetail job = JobBuilder.Create<HelloJob>()
.WithIdentity("job1", "group1")
.Build();
// Trigger the job to run now, and then repeat every 10 seconds
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(10)
.RepeatForever())
.Build();
// Tell quartz to schedule the job using our trigger
scheduler.ScheduleJob(job, trigger);
I need to do something with the database inside of HelloJob.Execute
, but since it is not a Controller
(and even if it was, it wouldn't get activated like one), I cannot inject the database into the constructor.