I have an interface:
public interface Irepos
{
string somefunction();
}
Then the class I want to use:
public class repos : Irepos
{
string somefunction()
{
return "function called";
}
}
Registered as singleton in startup.cs:
services.AddSingleton<Irepos, repos>();
Now I can use it like this in my controller class:
public class controller
{
private readonly Irepos interfaceRepos;
public ValuesController(Irepos reposInerface)
{
interfaceRepos = reposInerface;
}
interfaceRepos.somefunction();
}
Now my question is: can I use the same instance of the same repos
class in a different class or different controller? Say:
public class AnotherController
{
private readonly Irepos interfaceRepos;
public ValuesController(Irepos reposInerface)
{
interfaceRepos = reposInerface;
}
interfaceRepos.somefunction();
}