Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Adding service initialization method when using Castle Windsor IoC container

If my service have some initialization code, I know two options:

  1. Implement ISupportInitialize.
    Pro: Only depend on .NET native interface.
    Con: I normally only use BeginInit(), so there's always unneccessary code of empty EndInit()

  2. Implement Castle Core's IInitializable.
    Pro: Only one method needs to be implemented.
    Con: I have to make my class depend on Castle Core.

Is there a better alternative?

like image 627
Louis Rhys Avatar asked Mar 25 '23 05:03

Louis Rhys

1 Answers

Yes there is:

Component.For<Foo>().OnCreate(foo => foo.WhateverMethodYouWant());

The details are in the documentation.

like image 179
Krzysztof Kozmic Avatar answered Apr 07 '23 15:04

Krzysztof Kozmic