English 中文(简体)
实现DI/IoC时将次要用户数据类型存储在何处
原标题:Where to store minor user data types when implementing DI/IoC

每次启动基于依赖注入的新解决方案时,我都会问自己一个同样的问题。我通常有一个专门用于接口的程序集——每个其他解决方案模块都引用这个程序集。如果我需要使用一些小的用户数据类型,我也会将它们存储在接口程序集中。这似乎是最合乎逻辑的事情,但它总是让惰性面组装项目看起来像一个垃圾箱。

问题是,SearchParamsSimpleTaskComplexTask最好放在哪里?请参考下面的例子。

That s how I use to do:
Common.Interfaces

interface IScheduler
{
    Boolean ScheduleTask(ITask task);
    ITask FindTask(SearchParameters search);
}

interface ITask { ... }

class SearchParameters { ... }

Common.Schedur

class Scheduler : IScheduler { ... }

class SimpleTask : ITask { ... }

class ComplexTask : ITask { ... }

SimpleTaskComplexTask的问题是,无论我在哪里调用IScheduler.ScheduleTask(…),都需要引用Common.Scheduler。SearchParameters问题是,它严重浪费了接口。想象一下,在同一个程序集中存储了数百个小类型。

最佳回答

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.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签