IOC:温莎城堡和的WebAPI [英] IoC: Castle Windsor and WebAPI

查看:136
本文介绍了IOC:温莎城堡和的WebAPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用温莎城堡,我想添加一些的WebAPI调用一个MVC4网站,所以我开始对周围interwebs一点点的挖。

I have an MVC4 site using Castle Windsor that I want to add some WebAPI calls to, so I start digging around a little bit on the interwebs.

现在我不知道国际奥委会的来龙去脉;我遵循了如何设置温莎城堡在我的项目的教程,注射 IUnitOfWorkFactory IApplicationService 的公共属性在碱的控制器,并根据需要在控制器的构造的几个其它接口。它的工作原理顺顺当当,所以我从来没有用它做更多。

Now I don't know the ins and outs of IoC; I followed a tutorial for how to set up Castle Windsor on my project, injecting the IUnitOfWorkFactory and the IApplicationService as public properties in a base controller, and a few other interfaces as needed in the controller constructors. It works swimmingly, so I've never had to do more with it.

到处说我上的WebAPI读书了,有人告诉我DI将无法工作,以及使用温莎城堡,谈论与的IDependencyResolver 和<$ C问题$ C> IDependencyScope 。有几种解决方法以及如何解决这个问题的实现,但什么是我不明白究竟是出了什么问题。 code片段都包括在内,但前提是你知道他们属于哪个阶层,他们是如何被调用,不幸的是我不知道。另外,我在网上看到的所有例子指独家的WebAPI项目,而不是一个MVC4项目与一对夫妇 ApiController S IN明智翻腾。我不知道如何,或者如果,这会影响任何东西。

Everywhere that I'm reading up on WebAPI, I'm told DI will not work so well using Castle Windsor, talking about problems with the IDependencyResolver and IDependencyScope. There are several workarounds and implementations of how to get around this problem, but what is not clear to me is what exactly the problem is. Code snippets are included, but the assumption is you know what class they belong to, and how they are invoked, which unfortunately I do not. Additionally, all the examples I've seen online refer to an exclusive WebAPI project, and not an MVC4 project with a couple ApiControllers judiciously tossed in. I don't know how, or if, this affects anything.

为什么不是我有我的标准控制器的工作不能与API控制器工作?什么样的code杂技需要做的就是的WebAPI电话和标准的网络电话在同一应用程序的工作?

Why won't what I have working with my standard controllers not work with an API controller? What kind of code acrobatics need to do to get WebAPI calls and standard web calls to work in the same application?

推荐答案

为了使用温莎用的WebAPI跟随
<一href=\"http://blog.ploeh.dk/2012/10/03/DependencyInjectioninASP.NETWebAPIwithCastleWindsor/\">http://blog.ploeh.dk/2012/10/03/DependencyInjectioninASP.NETWebAPIwithCastleWindsor/
(BEH:固定链接)

In order to use Windsor with webapi follow http://blog.ploeh.dk/2012/10/03/DependencyInjectioninASP.NETWebAPIwithCastleWindsor/ (BEH: fixed link)

也读
<一href=\"http://stackoverflow.com/questions/15736402/castle-windsor-delegatinghandler-iprincipal-dependency-injection-di-inversion/15758982#15758982\">Castle温莎/ DelegatingHandler / IPrincipal的依赖注入(DI)中的ASP.NET Web API 控制(IOC)的/反转

Read also Castle Windsor/DelegatingHandler/IPrincipal Dependency Injection (DI)/Inversion of Control (IoC) in ASP.NET Web API

您可以使用的WebAPI和MVC控制器在同一应用程序(我preFER使其保持独立的),但路由和控制器工厂是不同的,你必须设置两个不同的配置和处理路由重叠...
对于MVC和放大器;温莎你可以找到一个伟大的

You can use webapi and MVC controllers in the same app (I prefer to keep it separate) but routing and controllers factory are different and you have to set up two different configuration and handle routing overlaps... For MVC & Windsor you can find a great

这篇关于IOC:温莎城堡和的WebAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆