Reputation: 10364
I have the following project structure in my solution:
Project.Repository (Class Library)
Project.Core (Class Library)
Project.Web (MVC5 web front end)
Project.Scheduler (Console Application)
I am using Unity to handle my DI.
My problem
I have a method which sits in the Core layer, this method has a dependency on an IProcessDataService
interface which is being handled in my Unity config.
//Service
container.RegisterType<IProcessDataService, ProcessDataService>(new PerRequestLifetimeManager());
I have most recently created my Console Application project which will basically invoke the said method and will be run on a windows schedule.
How do I go about accessing this method from my Console Application's static Main method considering I have a dependency to my core interface?
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Begin Automation Process");
//Run method from Core layer which has a dependency on IProcessDataService
}
}
Upvotes: 1
Views: 772
Reputation: 32936
your console app's main method is your composition root and you should be doing all of your wiring up in there.
Then you can resolve your object from the container and call the method on it.
Upvotes: 3