How to use Castle.Windsor in an assembly loaded using reflection

前端 未结 3 2068
Happy的楠姐
Happy的楠姐 2021-01-07 00:26

Let\'s say I have a library Lib.dll, which uses Castle.Windsor to initialize its services.

I have a main application App.exe, which loads Lib.dll on runtime using re

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 01:12

    You probably can't do it in easy and elegant way if App.exe doesn't provide you Castle Windsor's container instance to configure your services.

    If it is not exposed directly, maybe you can access it using Service Locator? Or find it on your own using reflection on App.exe assembly?

    The best solution will be if code in App.exe calls specific method in your library (i.e. it can look for particular interface implementation, like IModuleInitializer or something, create an instance of it and call some kind of Initialize method passing container instance to your code).

    You could also think about extensibility frameworks like MEF, but that can be a bit overkill and make big influence on App.exe.

提交回复
热议问题