C# 如何使业务层使用不同的模型?
我正在用C#设计一个.Net项目的体系结构。 我将使用EF。 我想设置一个MVC模式架构。 虽然我将从第一个模型实现开始,但我可能必须使用与原始模型非常相似的其他模型 我显然想要实现一个单一的业务层,理想情况下,它可以与两个模型实现一起工作 因此,我想我将不得不在某一点上强烈依赖接口 通常,我以这种方式构建实体和上下文:C# 如何使业务层使用不同的模型?,c#,model-view-controller,interface,n-tier-architecture,C#,Model View Controller,Interface,N Tier Architecture,我正在用C#设计一个.Net项目的体系结构。 我将使用EF。 我想设置一个MVC模式架构。 虽然我将从第一个模型实现开始,但我可能必须使用与原始模型非常相似的其他模型 我显然想要实现一个单一的业务层,理想情况下,它可以与两个模型实现一起工作 因此,我想我将不得不在某一点上强烈依赖接口 通常,我以这种方式构建实体和上下文: public class Foo { public int Id { get; set; } public string Name { ge
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
... other properties
}
public class Bar
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Foo Fooo { get; set; }
... other properties
}
...
public class MyContext : DbContext
{
...
}
现在,在我的例子中,我将有两个不同的模型。
在先前编写的Foo和Bar类的基础上,我将有:
public class Foo2
{
public int Id { get; set; }
public string Name { get; set; }
... other properties
}
public class Bar2
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Foo Fooo { get; set; }
... other properties
}
...
public class MyContext2 : DbContext
{
...
}
现在,如何设置一个可以处理MyContext或MyContext2的业务层
我认为第一步是为Foo/Foo2和Bar/Bar2创建接口:
public interface IFoo
{
int Id { get; set; }
string Name { get; set; }
}
public interface IBar
{
int Id { get; set; }
string Name { get; set; }
IFoo Fooo { get; set; }
}
然后呢