I have two projects when the first one runs he injects dependencies, when the second runs he injects some to himself aswell. I have a class called "SchedulerImpl" in the first project that looks like this:
public class SchedulerImpl: ISche
{
private IScheduler _scheduler;
private string _uniqueId { get; set; }
private string _userId;
public SchedulerImpl(IScheduler scheduler)
{
_scheduler = scheduler;
}
as you can see the constructor takes IScheduler type.
in project #2 I am trying to inject "SchedulerImpl" class(which belongs to project #1) and I need to also inject the IScheduler that the constructor injects, any ideas on how to do that? I was looking at the documentation but it is too damn confusing.. any help would be appreciated
You should register the IScheduler
, e.g. as a singleton:
builder.RegisterInstance(QuartzInstance.Instance).AsImplementedInterfaces();
and then the class that uses it:
builder.RegisterType<SchedulerImp>().AsImplementedInterfaces();
and let the container resolve them for you. You shouldn't need to do this manually unless there are specific things you need to pass to the constructor that can't be resolved.
If you have two projects and need each to register a bunch of classes or singletons with the container, use a Module
in Autofac.