English 中文(简体)
MVC 3 继承实体
原标题:MVC 3 passing entity as an Interface

目前,Im公司正在使用Ninject作为我的DI开展一个MVC 3项目,这些商业物体储存在单独的组中。 I m 转而处理控制器参数的问题,在为CRUD业务投递时,I m 发现错误“没有造成接口的事例”。 我知道,你可以开创一个接口的事例,但似乎我可以采取的唯一办法就是使用一种习俗模式约束器,并通过表格集。 这似乎真是令人迷惑的,我希望像我能够那样,把具体的代码排出项目,从而把每个地方和Ninject之间的接口与具体细节联系起来。 习俗模式不仅具有约束力,而且似乎很不舒服,我也失去了我的数据集?

某些法典描述我拥有的东西:

public ActionResult Create()
{
    // I m thinking of using a factory pattern for this part
    var objectToCreate = new ConcereteType();
    return (objectToEdit);
}

[HttpPost]
public ActionResult Create(IRecord record)
{
    // check model and pass to repository
    if (ModelState.IsValue)
    {
        _repository.Create(record);
        return View();
    }

    return View(record);
}

是否有人这样做? 你是如何接手的?

感谢!

最佳回答

用于控制者行动的数据只是价值观的持有者。 他们中没有任何逻辑,因此没有任何东西可以脱节。 你可以使用具体类型(例如记录),而不是接口(记录)。

问题回答

但是,似乎像我能够做到这一点的唯一途径是使用约束器的习惯模式。

习俗模式约束器是正确的道路。 并且,你应当将模型作为行动论点,而不是域模型或接口。

习俗模式不仅具有约束力,而且似乎很不舒服,我也失去了我的数据集?

我不知道,为什么你认为,习惯模式会使事情变得.。 对我来说,将制图逻辑划分为可再利用的类别是大有可为的。 而且,没有人会失去数据年度。 他们将在习俗模式约束者返回这一具体情况下进行完美的工作。

我犯了同样的简单错误。 Ninject给你的建筑商注入参数,但你在索引主计长的行动中增加了参数。

它希望:

public class HomeController : Controller
{
    private IRecord _record;

    public HomeController(IRecord record)
    {
        _record = record;
    }

    public ActionResult Index()
    {
        ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application. " +
                          _record .HelloWorld();

        return View();
    }
}

是否有意义?





相关问题
How to Inject Open Connections with an IoC

First, my scenario. I have a service, BillingService, has a constructor like this: BillingService(IInstallmentService, IBillingRepository) The InstallmentService has a constructor that looks like ...

Using the Ninject kernel as a Unit of Work object factory

So I m starting to use Ninject for dependency injection and I m wondering what people think of using a kernel as an object factory for Unit of Work type objects like Linq2Sql Datacontexts. I would ...

array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Unity constructors

I have setup unity in my project and it is working for objects that don t have constructor injection implemented on them. The issue is now I do have an object which requires a custom object as a ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

ASP.NET MVP Injecting Service Dependency

I have an ASP.NET page that implements my view and creates the presenter in the page constuctor. Phil Haack s post providing was used as the starting point, and I ll just the examples from the post ...

Authorization and Windsor

I m trying to implement my custom authorize attribute like: public class MyCustomAuth : AuthorizeAttribute { private readonly IUserService _userService; public MyCustomAuth(IUserService ...

热门标签