开发者

Where to store minor user data types when implementing DI/IoC

开发者 https://www.devze.com 2023-03-09 18:03 出处:网络
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 isreferenced by each a

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 ITa开发者_Python百科sk { ... }

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.Scheduler when you call IScheduler.ScheduleTask? This method correctly uses the interface, so calling this method doesn't require you to reference Common.Scheduler.
You only need to reference that assembly if you are working with one of the concrete types SimpleTask or ComplexTask. In that case, it is correct that you need to reference that assembly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号