I have a WCF service which calls the business component which calls the repository and I have got it end to end working using Castle Windsor using it's WCF Facility.
The WCF Facility registration and rest of the component registration happens in the Global.asax file like this.
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>() ); } }
All is well but now I need to refer this container in one of my component so that I can resolve other components like this.
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(); } }
Moreoever I want this container to be available globally and don't want to run registration over and over again, So should I look into shuving this container in HttpRuntime.Cache so it is available and any component can simple get it from Cache and resolve what ever interface they want to.
Pardon my ignorance as I am new to WCF and as well Castle Windsor and the whole architecture has been shuved down my throat with a steep deadline :-(