how i can register and use class like that:
class MyClass{
private MyClass{}
public getInstance(){
return myClass;
}
}
Or what I need to change that the class remained singleton and I could use it as singleton in autofac?
how i can register and use class like that:
class MyClass{
private MyClass{}
public getInstance(){
return myClass;
}
}
Or what I need to change that the class remained singleton and I could use it as singleton in autofac?
When using DI like autofac, just register the class as a singleton in the setup process. The DI container will handle the rest for you. As long as the class is injected, you don't need to handle setting up the class as a singleton yourself.
Autofac's method for this is .SingleInstance()
. See the documentation