-1

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?

mak_27
  • 9
  • 3
  • 1
    Does this even **compile**? If not, please review before posting and please update to include expected output, a specific issue and replicate code to help you. – Trevor Oct 05 '20 at 14:56
  • Does this answer your question? [What is a singleton in C#?](https://stackoverflow.com/questions/2155688/what-is-a-singleton-in-c) – Zig Razor Oct 06 '20 at 08:06

1 Answers1

1

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

Jonesopolis
  • 25,034
  • 12
  • 68
  • 112