I have a .NET Core (UWP solution) application which has 3 different projects (let's call them A, B and C).
A and B are Windows Runtime Components, and C is a simple Class Library.
Projects A and B have a reference to the project C.
I would like to access a class of the project C, whose the instance would be shared between projects A and B.
I thought to a singleton pattern (of course), using the Lazy method of .NET 4
Problem is that the instance is not the same each time A and B projects access the instance. The Lazy method creates a new instance of the class because it seems not to be previously created. I wonder if I can share a singleton between different projects of a solution. I've read that a project is associated to a process, and each process has its own memory space which cannot be shared. Is there a solution to my issue?
EDIT: Here's my implementation of my HubService class:
private static readonly Lazy<HubService> Lazy =
new Lazy<HubService>(() => new HubService(), LazyThreadSafetyMode.ExecutionAndPublication);
private HubService()
{
_asyncQueue = new AsyncQueue<Guid>();
}
public static HubService Instance => Lazy.Value;
Also, is it possible to share a singleton across different assemblies using tools like Castle Windsor, Ninject, Autofac or Unity?