I am trying to run non static method from static and use dependency Injection inside non static method. (I am trying to do this inside one class)
My code looks like this:
public class Tokens
{
private IRefreshTokenRepository refreshTokenRepository;
public Tokens(IRefreshTokenRepository refreshTokenRepository)
{
this.refreshTokenRepository = refreshTokenRepository;
}
// I understand that problem is there, but I should to write this
//constructor because otherwise I can not use class variable in static method
public Tokens()
{
}
public static async Task<string> GenerateJwt()
{
RefreshToken rf = new RefreshToken{...};
Tokens t = new Tokens();
t.StoreRefToken(rf);
return JsonConvert.SerializeObject(...);
}
public async void StoreRefToken(RefreshToken reft)
{
this.refreshTokenRepository.InsertRefreshToken(reft);
await refreshTokenRepository.SaveAsync();
}
}
As you understand from code, when I wrote "Tokens t = new Tokens();" this code had used constructor without importing repository. What to do? Can I fix it inside single class?
Thank you
P.S. if question is silly I'm sorry