I'm trying to set up an object to be a singleton using Unity, but the object is being created every time I make a request.
public class ShareTubeRoomRepository : IShareTubeRoomRepository
{
public ShareTubeRoomRepository()
{
//load my base data
}
Unity Configuration
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterInstance<IShareTubeRoomRepository>(new ShareTubeRoomRepository(), new ContainerControlledLifetimeManager());
}
I have also tried the following:
container.RegisterType<IShareTubeRoomRepository, ShareTubeRoomRepository>(new ContainerControlledLifetimeManager());
I put a breakpoint at the constructor for the repository and it's being called every time a page loads in my MVC application. Every resource I've found has said that these methods of registering the type should create it as a singleton, so why is it recreating this instance every request?
I tried making the data that I want to store static so it won't get refreshed, and instantiating it in the static constructor, but even the static constructor is getting called multiple times. According to this answer: https://stackoverflow.com/a/5119154/526704 that shouldn't be happening, right?