小编Wil*_*iam的帖子

如何用IOC替换switch语句,以便我可以保持SOLID原则

我想避免使用switch语句.我有30多种文档类型.还有可能我需要添加更多的文档类型.我宁愿传递IDocument并且具有在IDocument的实现中指定的类型.我忘了提到的其他东西是ProgressNoteViewModel,LabViewModel ...都继承自WorkspaceViewModel,所有具体实现构造函数都将类型IPatient作为参数.我也使用Castle作为我的IoC容器

我想将代码重构为类似的东西

viewModel = new TreeViewModel(repository.GetPatientDocumentListing(IDocumentType);
this.DocTreeViewModel = viewModel;
//How would I then be able to instantiate the right ViewModel
//based on IDocumentType and also pass a object into the
//constructor that is not know at compile time
Run Code Online (Sandbox Code Playgroud)

我有以下代码:

switch (docType)
{
    case "ProgressNotes":
        viewModel = new TreeViewModel(repository.GetPatientProgressNotes());
        this.DocTreeViewModel = viewModel;
        ProgressNoteViewModel workspace = ProgressNoteViewModel.NewProgressNoteViewModel(_patient);
        break;
    case "Labs":
        viewModel = new TreeViewModel(repository.GetPatientLabs());
        this.DocTreeViewModel = viewModel;
        LabViewModel workspace = LabViewModel.NewLabViewModel(_patient);
        break;
}
this.Workspaces.Add(workspace);
this.SetActiveWorkspace(workspace);
Run Code Online (Sandbox Code Playgroud)

c# inversion-of-control switch-statement solid-principles

7
推荐指数
1
解决办法
1769
查看次数

具有接口作为返回类型的实体框架和建模集合

我正在使用Entity Framework v4.我创建了一个包含一堆标量属性的POCO类和一个返回Interface类型的集合.如何在EF模型中创建此关系?如何显示包含不同项目的集合,但它们都具有通用界面?这将是我想要实现的一个例子.

interface IPatientDocument{}
public class Lab : IPatientDocument{.....}
public class Encounter : IPatientDocument{...}
public class MedicationLog : IPatientDocument{...}

//Incomplete class listing
//Once I have aggregated the different doc types, I can then use Linq to Obj to retrieve the specific doc type I need.  Currently I have about 26 doc types and do not want to create a collection for each one
public class Patient
{
   IList<IPatientDocument> DocumentCollection;
}
Run Code Online (Sandbox Code Playgroud)

c# entity-framework poco

6
推荐指数
1
解决办法
805
查看次数

使用EF 4和DDD的最佳方法是什么?

我想在我的DDD项目中使用EFf 4作为我的ORM.我将根据我的类生成我的模型.我应该为消费者创建业务对象的基本dto对象的类,还是应该在EF模型中实现实际的BO类?

domain-driven-design entity-framework ddd-repositories

5
推荐指数
1
解决办法
422
查看次数