简体   繁体   English

如何在无svc服务实现中使用Simple Injector

[英]How to use Simple Injector with svc-less service implementations

I'm considering switching from Autofac to Simple Injector due to seemingly better decorator support. 由于考虑到更好的装饰器支持,我正在考虑从Autofac切换到Simple Injector。 But I'm very fond of the way you register and host svc-less WCF services with Autofac and I can't find a way to do exactly that with Simpleinjector. 但是我非常喜欢您使用Autofac注册和托管无svc的WCF服务的方式,而我找不到使用Simpleinjector做到这一点的方法。

For instance, with Autofac it works like this (in Application_Start): 例如,使用Autofac,它的工作方式如下(在Application_Start中):

During container build: 在容器构建期间:

builder.RegisterType<SomeService>().As<ISomeService>();

After the container has been constructed: 构造容器后:

RouteTable.Routes.Add(
    new ServiceRoute("", new AutofacServiceHostFactory(), typeof(ISomeService)))

Please note the empty-string routePrefix in the ServiceRoute in order to achieve rest-style service-endpoints without an actual service-name in the url. 请注意ServiceRoute中的空字符串routePrefix,以实现REST风格的服务端点,而网址中没有实际的服务名称。

Is there an equivalent to this in Simple Injector? 在简单注入器中有与此等效的东西吗?

Just use: 只需使用:

SimpleInjectorServiceHostFactory.SetContainer(container);

RouteTable.Routes.Add(
    new ServiceRoute("", 
        new SimpleInjectorServiceHostFactory(),
        typeof(ISomeService)));

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

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