0
Hello, I’m starting my studies with Oauth, and right away I came across a problem. I created the famous 'Startup' class, and in it I call my predecessor as follows:
public partial class Startup
{
public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
public void Configuration(IAppBuilder app)
{
app.UseOAuthBearerTokens(OAuthOptions);
}
static Startup()
{
OAuthOptions = new OAuthAuthorizationServerOptions
{
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/autenticar"),
/*chamada do provider*/
Provider = new OAuthProvider()
};
}
}
But the constructor of this class applies a dependency injection to the constructor as follows:
IUsuariosServices _usuariosServices;
public OAuthProvider(IUsuariosServices usuariosServices)
{
_usuariosServices = usuariosServices;
}
In order to be able to perform the functions inserted in this interface.
Thus remaining:
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
return Task.Factory.StartNew(() =>
{
string email = context.UserName;
string senha = context.Password;
/* Chamada da função da injeção de dependências */
var usuario = _usuariosServices.Login(email, senha);
});
}
But in my 'Startup' class, in the Provider class call an error occurs asking for a class parameter!
error message
The problem is? What parameter is this? How to pass as a parameter an injection of dependencies? That’s what you have to do?
Thank you in advance...
In fact, this doesn’t make much sense, because I just pass an interface and there’s no way to initiate an interface. It is dependency injection, where I inform which class that interface represents and the instance of it is created in the constructor of the class that will use it
– Guilherme Nunes
You’re not going to pass an interface, it turns out you need an instance that implements that interface. In the startup class there is no constructor, if not you could inject dependency there too
– Barbetta
Could show an example?
– Guilherme Nunes
@Guilhermenunes I added 1 example, I do not know if it was didactic, but I will try to improve the evening.
– Barbetta
Aeh, boy, it worked fine, thank you very much.
– Guilherme Nunes
@Guillhermenunes Wonder, if there is any doubt, I’m happy to try to answer ;)
– Barbetta