改变内部密封类? [英] Change internal seal class?

查看:72
本文介绍了改变内部密封类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内部课程:

I have an internal class:

internal sealed class SharedState



解决方案中有大约900个引用。所有方法都是静态的。

其中一种方法是日志消息。出于某种原因,我们在库中创建了其他记录器并准备替换旧的日志方法。



现在我们必须将记录器传递给此内部密封类客户项目。



有可能吗?



更新:我是将使用构造函数。


It has about 900 references in the solution. All the methods are static.
One of them methods is for log message. For some reason, we created other loggers in a library and ready to replace the old log method.

Now we have to pass the loggers to this internal sealed class from the client projects.

Is it possible?

Updated: I am going to use the constructor.

public static ILogger _logger;
        public SharedState(ILogger logger)
        {
            _logger = logger;
        }



但是,在客户端项目中,我们必须新建记录器。可以吗?

但是其他方法,我们仍然直接称它们为:

SharedState.OneMethod(str);

在其他地方,我们使用

SharedStateInstance.LogInfo(logMessage);

混合直接调用和实例调用的排序。


However, in the client project, we have to new up logger. Is it okay?
But other methods, we still directly call them as:
SharedState.OneMethod(str);
In other place, we use
SharedStateInstance.LogInfo(logMessage);
Sort of mixing direct call and instance call.

推荐答案

根据您提供的信息,无法分辨。



如果你在这个密封的类中使用了依赖注入,那么你所要做的就是确保你的新登录类正在使用注入所需的接口。



如果没有,那么,您将不得不更改密封类,以便以某种方式使用新类型传递记录器。当然,这将改变课程,你可能会破坏你所拥有的所有900个参考文献。
With the information you provided, it's impossible to tell.

If you used dependency injection in this sealed class, then all you would have to do is make sure your new logged class is using the interface the injection is looking for.

If not, well, you're going to have to change the sealed class to let you pass the logger in somehow using the new type. This will, of course, change the class and you might be breaking all 900 references you have to it.


这篇关于改变内部密封类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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