c# - 使用 CaSTLe Windsor 的 WCF 依赖注入(inject) - 请帮忙?

标签 c# wcf dependency-injection castle-windsor

我有一个 WCF 服务,该服务调用调用存储库的业务组件,我已经使用它的 WCF 工具使用 CaSTLe Windsor 端到端地工作。

WCF 工具注册和其余组件注册发生在 Global.asax 文件中,如下所示。


    public class Global : System.Web.HttpApplication
    {
        public IWindsorContainer SystemContainer;

        protected void Application_Start(object sender, EventArgs e)
        {
            RegisterDependencies();
        }

        private void RegisterDependencies()
        {
            SystemContainer = new WindsorContainer();


            SystemContainer.AddFacility<WcfFacility>().Register(
                Component.For<IBookingRepository>().ImplementedBy<BookingRepository>(),
                Component.For<IBookingBll>().ImplementedBy<BookingBll>(),
                Component.For<IBookingService>().ImplementedBy<BookingService>(),
                Component.For<ILogger>().ImplementedBy<Logger>()

                );
        }

    }

一切都很好,但现在我需要在我的组件之一中引用此容器,以便我可以像这样解析其他组件。

public class BookingBll : IBookingBll { private IBookingRepository _repository; private ILogger _logger; public BookingBll(IBookingRepository repository) { _repository = repository; _logger = SystemContainer.Resolve<ILogger>(); // This will not //compile as we can't access a Global class property. } public void Add(Booking booking) { //Some implementation; _logger.Write(); } }

而且我希望这个容器在全局范围内可用并且不想一遍又一遍地运行注册,所以我应该考虑在 HttpRuntime.Cache 中隐藏这个容器以便它可用并且任何组件都可以简单地从缓存中获取它并解决他们想要的任何界面。

请原谅我的无知,因为我是 WCF 和 CaSTLe Windsor 的新手,并且整个架构在一个陡峭的截止日期前被推到了我的喉咙里:-(

最佳答案

关于c# - 使用 CaSTLe Windsor 的 WCF 依赖注入(inject) - 请帮忙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3920784/

相关文章:

c# - 许多应用程序中的项目引用完整性

c# - 无法从 Task<> 隐式转换类型

c# - []、get_Item() 和 Item[] 之间的 Excel Interop 区别

c# - HttpContext.Current 在 Identity Framework 的方法中为 null

java - Guice 绑定(bind) API 示例

wcf - 向出现在 WSDL 中的 WCF Web 服务添加描述

javascript - 将信息从 WCF 发送到 JavaScript

.net - 不使用证书保护 WCF WebService

c# - 使用 Unity 代替 ASP.Net Core DI IServiceCollection

java - 如何在不专门使用 Spring ApplicationContext 的情况下检索 beansOfType(Class) 列表?