如何在nuget库中管理Castle Windsor依赖项 [英] How to manage Castle Windsor dependencies in a nuget library

查看:75
本文介绍了如何在nuget库中管理Castle Windsor依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组WebApi,MVC和Windows服务应用程序以及一个日志库(基于nLog).日志记录库打包为nuget(如果有的话).所有客户端和日志记录库都使用Castle Windsor.日志记录库具有一组复杂的依赖关系,目前在所有使用它的项目中,我都粘贴了大量的注册信息.

I have a set of WebApi, MVC and windows service apps and a logging library (based on nLog). The logging library is packaged as a nuget (if that matters). All the clients and the logging library use Castle Windsor. The logging library has a complex set of dependencies and currently in all the projects that use it I pasted a big block of registrations.

是否有一种方法可以使库使用一组默认依赖项(在其中自动注册)并仅在客户端需要非默认选项时更改它们?

Is there a way to make the library use a set of default dependencies (registered automatically inside it) and change those in the clients only if they need a non-default option?

推荐答案

您可以创建

You can create an installer for managing the dependencies:

public class RepositoriesInstaller : IWindsorInstaller
{
   public void Install(IWindsorContainer container, IConfigurationStore store)
   {
      //container.Register();
   }
}

然后客户端可以将其安装在其容器中,如下所示:

Then the clients can install it in their container like this:

container.Install(new RepositoriesInstaller());

您可以将此安装程序包含在库中(这意味着您的库将依赖于Castle Windsor),也可以创建另一个包含安装程序的软件包(MyLib.CastleWindsor等).

You can either include this installer in your library (that would mean your library would be dependent upon Castle Windsor) or create another package (MyLib.CastleWindsor etc) that contains the installer.

这篇关于如何在nuget库中管理Castle Windsor依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆