30 lines
738 B
C#
30 lines
738 B
C#
namespace api.Services;
|
|
|
|
// Imaginons que cette interface se trouve du côté applicatif et est utilisée par le contrôleur
|
|
public interface TokenGenerator
|
|
{
|
|
string Generate();
|
|
}
|
|
|
|
// Cette classe se trouve dans le projet d'infrastructure
|
|
public class JwtTokenGeneratorOptions
|
|
{
|
|
public string Token { get; set; } = string.Empty;
|
|
}
|
|
|
|
// Et est injectée ici
|
|
public class JwtTokenGenerator : TokenGenerator
|
|
{
|
|
private readonly JwtTokenGeneratorOptions _options;
|
|
|
|
public JwtTokenGenerator(JwtTokenGeneratorOptions options)
|
|
{
|
|
_options = options;
|
|
}
|
|
|
|
public string Generate()
|
|
{
|
|
// Ici tu as ton code permettant de gérer le fameux jeton à partir des options.
|
|
return _options.Token;
|
|
}
|
|
} |