【发布时间】:2017-07-12 09:57:37
【问题描述】:
我正在使用 Castle Windsor v3.4.0 创建 RavenDB 文档会话实例,但是当我使用 3.0.3660 之后的 RavenDB 客户端版本时,调用 Store 方法时出现此错误:
Castle.MicroKernel.ComponentNotFoundException: 'No component for supporting the service System.Net.Http.HttpMessageHandler was found'
这是我能想到的重现错误的最小片段代码:
using Castle.Facilities.TypedFactory;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Raven.Client;
using Raven.Client.Document;
public class Program
{
public static void Main()
{
var container = new WindsorContainer();
container.AddFacility<TypedFactoryFacility>();
container.Register(
Component
.For<IDocumentStore>()
.ImplementedBy<DocumentStore>()
.DependsOn(new { Url = "http://localhost:8081", DefaultDatabase = "Test" })
.OnCreate(x => x.Initialize())
.LifeStyle.Singleton,
Component
.For<IDocumentSession>()
.UsingFactoryMethod(x => x.Resolve<IDocumentStore>().OpenSession())
.LifeStyle.Transient);
using (var documentSession = container.Resolve<IDocumentSession>())
{
documentSession.Store(new object());
documentSession.SaveChanges();
}
}
}
这就是我认为正在发生的事情。在 v3.0.3660 之后对 RavenDB 客户端进行了更改,更改了在 HttpJsonRequest 类中创建 HttpMessageHandler 的方式:
https://github.com/ravendb/ravendb/commit/740ad10d42d50b1eff0fc89d1a6894fd57578984
我相信,这种更改与我在 Windsor 容器中使用 TypedFactoryFacility 相结合,导致 RavenDB 请求 HttpJsonRequestFactory 的实例,它是 Windsor 的依赖项,而不是使用它自己的内部依赖项。
如何更改我的代码以避免此问题,以便我可以使用更新版本的 RavenDB 客户端?
【问题讨论】:
标签: castle-windsor ravendb factory