Can I look forward to creating instances registered as singles using the castle's windsor?

In the castle windsurfer, when registering instances with a singleton life cycle, is there a way to instantiate them (instead of initializing them the first time they are entered)?

Update:

I thought some details would be useful here:

  • These instances contain an initialization code that will be useful to run at startup time, so I'm interested in this.
  • I am registering a lot of such instances with AllTypes.Pick(), so I would prefer a solution that would not include me in that I manually resolved each instance from the container separately after it was created.
+3
source share
1 answer

Yes, you can use the Startable Facility (which comes out of the box with Windsor):

container.AddFacility<StartableFacility>(
// optionally in v2.5
f=> f.DeferredStart()
);
container.Register(
   AllTypes.FromThisAssembly()
      .Pick().WhateverYouWant()
      .Configure(c => c.Start());

DeferredStartnew method v2.5 and you can see here what it does and why it is recommended that it be used. Samples use some new API in version 2.5, but if you are using v2.1, it should give you an idea of ​​how to achieve this.

In previous versions, the method Start()is calledStartable()

+4
source

Source: https://habr.com/ru/post/1756208/


All Articles