We have an external project with a QCServiceLog class that has a ILogging dependency which is resolved by Unity. But QCServiceLog is a Singleton class as you can see in the following example:
private readonly ILogging _logging = null;
private static QCServiceLog _instance = null;
public static QCServiceLog Instance
{
get
{
return _instance;
}
}
public QCServiceLog(ILogging logging)
{
_logging = logging;
if (_instance == null)
{
_instance = this;
}
}
We are trying to use it, and in our solution we did the registration like:
uc.RegisterType<ILogging, QCFileManager>(new ContainerControlledLifetimeManager());
But since QCServiceLog is a Singleton we believe that the code never gets through the constructor, then _instance is never instantiated. We are using it doing this:
QCServiceLog.Instance.Log(ex);
Is that Singleton implemented correctly? We believe that it´s never doing a new of QCServiceLog.
What do you think? Is there anything that we can do without changing the external project? The exception as you can imagine is:
Object reference not set to an instance of an object.
I would really appreciate your help!