Click here to Skip to main content
15,566,102 members
Home / Discussions / C#
   

C#

 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
dan!sh 21-Aug-18 5:41
professional dan!sh 21-Aug-18 5:41 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
Member 1204569221-Aug-18 9:34
Member 1204569221-Aug-18 9:34 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
Dave Kreskowiak21-Aug-18 10:29
mveDave Kreskowiak21-Aug-18 10:29 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
OriginalGriff21-Aug-18 5:59
mvaOriginalGriff21-Aug-18 5:59 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
Member 1204569221-Aug-18 9:30
Member 1204569221-Aug-18 9:30 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
OriginalGriff21-Aug-18 9:38
mvaOriginalGriff21-Aug-18 9:38 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
Member 1204569221-Aug-18 21:27
Member 1204569221-Aug-18 21:27 
AnswerRe: Use custom services inside OAuthorizationProviders Pin
Richard Deeming22-Aug-18 3:40
mveRichard Deeming22-Aug-18 3:40 
It sounds like you're trying to use Dependency Injection with your provider instances. It's not simple, but there are a few suggestions in this StackOverflow thread[^].

For example:
C#
public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var container = SimpleInjectorConfig.Register();

        GlobalConfiguration.Configure(WebApiConfig.Register);

        Func<IAuthService> authServiceFactory = () => container.GetInstance<IAuthService>();

        var OAuthServerOptions = new OAuthAuthorizationServerOptions
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/token"),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
            Provider = new SimpleAuthorizationServerProvider(authServiceFactory),
            RefreshTokenProvider = new SimpleRefreshTokenProvider(authServiceFactory),
        };

        // Token Generation
        app.UseOAuthAuthorizationServer(OAuthServerOptions);
        app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
    }
}

Your provider classes will need to be changed to take a Func<IAuthService> delegate instead of an IAuthService instance. Whenever they need an IAuthService instance, they call the factory delegate.
C#
public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider
{
    private readonly Func<IAuthService> _authServiceFactory;

    public SimpleAuthorizationServerProvider(Func<IAuthService> authServiceFactory)
    {
        _authServiceFactory = authServiceFactory;
    }
    
    ...
    
    // Eg:
    public override Task GrantAuthorizationCode(OAuthGrantAuthorizationCodeContext context)
    {
        IAuthService authService = _authServiceFactory();
        ...
    }




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

Questionhelp to solve C# codes Pin
Ali 2Fan19-Aug-18 10:32
Ali 2Fan19-Aug-18 10:32 
AnswerRe: help to solve C# codes Pin
OriginalGriff19-Aug-18 10:34
mvaOriginalGriff19-Aug-18 10:34 
AnswerRe: help to solve C# codes Pin
Dave Kreskowiak20-Aug-18 11:49
mveDave Kreskowiak20-Aug-18 11:49 
QuestionHow to Merge DataGridView Cell in Winforms ? Pin
Member 245846715-Aug-18 18:32
Member 245846715-Aug-18 18:32 
AnswerRe: How to Merge DataGridView Cell in Winforms ? Pin
dan!sh 16-Aug-18 4:20
professional dan!sh 16-Aug-18 4:20 
QuestionC# add usb device to appxmanifest capabilities for Bosch BNO055 Pin
RAFish040415-Aug-18 9:48
RAFish040415-Aug-18 9:48 
AnswerRe: C# add usb device to appxmanifest capabilities for Bosch BNO055 Pin
Richard Andrew x6415-Aug-18 13:37
professionalRichard Andrew x6415-Aug-18 13:37 
GeneralRe: C# add usb device to appxmanifest capabilities for Bosch BNO055 Pin
RAFish040415-Aug-18 14:41
RAFish040415-Aug-18 14:41 
QuestionWhich language and IDE would require less coding for my test program? Pin
Member 1297423513-Aug-18 16:24
Member 1297423513-Aug-18 16:24 
AnswerRe: Which language and IDE would require less coding for my test program? Pin
OriginalGriff13-Aug-18 20:49
mvaOriginalGriff13-Aug-18 20:49 
AnswerRe: Which language and IDE would require less coding for my test program? Pin
Richard MacCutchan13-Aug-18 22:31
mveRichard MacCutchan13-Aug-18 22:31 
AnswerRe: Which language and IDE would require less coding for my test program? Pin
Eddy Vluggen14-Aug-18 1:51
professionalEddy Vluggen14-Aug-18 1:51 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
Mycroft Holmes14-Aug-18 2:30
professionalMycroft Holmes14-Aug-18 2:30 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
Eddy Vluggen14-Aug-18 3:25
professionalEddy Vluggen14-Aug-18 3:25 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
Dave Kreskowiak14-Aug-18 4:30
mveDave Kreskowiak14-Aug-18 4:30 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
OriginalGriff14-Aug-18 4:54
mvaOriginalGriff14-Aug-18 4:54 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
Richard MacCutchan14-Aug-18 6:49
mveRichard MacCutchan14-Aug-18 6:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.