简体   繁体   English

WebAPI ODATA —使用标准控制器/ Ioc /存储库/ UoW排序体系结构与MVC一起使用

[英]WebAPI ODATA — Consuming With MVC Using Standard Controller/Ioc/Repository/UoW Sort of Architecture

Working with WebAPI ODATA services with javascript is not a problem... but what is a current recommendation to wrap the http calls (CRUD) to be consumed through a MVC5 application with a repository. 使用带有javascript的WebAPI ODATA服务不成问题...但是当前的建议是,包装带有存储库的MVC5应用程序使用的http调用(CRUD)。 Much of the guidance I see ultimately goes directly to the entity/dbcontext. 我最终看到的许多指导最终直接用于实体/ dbcontext。 I am looking for guidance which demonstrates the "drinking of your own Kool-Aid" and consuming the same ODATA (and it can be plain WebAPI, also) published externally to consumers of an application. 我正在寻找指导,以演示“饮用自己的Kool-Aid”并使用在应用程序的外部发布的相同ODATA(也可以是普通的WebAPI)。

In my mind, I'm looking at this sort of flow: AppController (site1:443)-->AppRepository-->OdataController (apiSite2:443)-->OdataRepository-->DataSource 在我看来,我正在研究这种流程:AppController(site1:443)-> AppRepository-> OdataController(apiSite2:443)-> OdataRepository-> DataSource

The secondary concern is that I don't necessarily want direct access to a datasource by any consumer--especially posts without being vetted and I don't want all (any) of the logic in the controller. 第二个问题是我不一定要让任何使用者直接访问数据源,尤其是在未经审查的情况下进行发布,并且我也不想控制器中的所有(任何)逻辑。 I might be overthinking something... 我可能在想什么...

In order to extract the business logic from the controller I typically either push said logic down to domain objects whenever possible. 为了从控制器中提取业务逻辑,我通常尽可能地将所述逻辑下推到域对象。 If that isn't possible, then I'll create a class specifically designed to manage the logic in question, such as an interaction between two different objects. 如果不可能,那么我将创建一个专门设计用于管理所讨论逻辑的类,例如两个不同对象之间的交互。

If all else fails, then I'll have the interaction managed by a service. 如果所有其他方法都失败了,那么我将由服务管理交互。 The classes might look something like the following: 这些类可能类似于以下内容:

public class SomeApiController : ApiController
{
    public SomeApiController(ISomeApiService service)
    {
       this.Service = service;
    }

    private ISomeApiService Service { get; set; }

    public IHttpActionResult SomeMethod(int someObjectId)
    {
        // service manages the logic and either defers to the object in question or resolves it through some specialized class
        var result = this.Service.SomeMethod(someObjectId);
        return this.OK(result);
    }
}

public class SomeApiService : ISomeApiService
{
    public SomeApiService(ISomeRepository repository)
    {
        this.Repository = repository;
    }

    private ISomeRepository Repository { get; set; }
}

... and so on. ... 等等。

The idea being that the layers have no dependencies upon one another which cannot be resolved through the IoC container of your choice and that the dependencies only go one way. 这样的想法是,各层之间没有相互依赖关系,而这些依赖关系无法通过您选择的IoC容器来解决,并且相互依赖关系只有一种方式。 That is to say SomeApiService has no dependency on SomeApiController and SomeApiRepository would have no dependency on SomeApiService. 也就是说,SomeApiService不依赖SomeApiController,SomeApiRepository不依赖SomeApiService。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM