There’s a same question I keep asking myself each time a new Dependency Injection based solution is being started. I usually have a dedicated assembly for interfaces – this one is referenced by each and every other solution modules. Should I need to use some small user data types, I use to store those in interfaces assembly also. This seems to be the most logical thing, however it always makes the inerface assembly project look like a trashbox.
And the question is – what’s the best place for SearchParams, SimpleTask and ComplexTask to be kept in? Please refer to the example below.
That’s how I use to do:
Common.Interfaces
interface IScheduler
{
Boolean ScheduleTask(ITask task);
ITask FindTask(SearchParameters search);
}
interface ITask { ... }
class SearchParameters { ... }
Common.Scheduler
class Scheduler : IScheduler { ... }
class SimpleTask : ITask { ... }
class ComplexTask : ITask { ... }
The problem with SimpleTask and ComplexTask here is it requires me to reference Common.Scheduler wherever I’m calling IScheduler.ScheduleTask(…). And the problem with SearchParameters is it wastes interface assmebly. Imagine there are hundreds of small types stored under the same assembly.
Why do you need to reference
Common.Schedulerwhen you callIScheduler.ScheduleTask? This method correctly uses the interface, so calling this method doesn’t require you to referenceCommon.Scheduler.You only need to reference that assembly if you are working with one of the concrete types
SimpleTaskorComplexTask. In that case, it is correct that you need to reference that assembly.