Click here to Skip to main content
15,881,687 members
Home / Discussions / C#
   

C#

 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
dan!sh 21-Aug-18 4:41
professional dan!sh 21-Aug-18 4:41 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
Member 1204569221-Aug-18 8:34
Member 1204569221-Aug-18 8:34 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
Dave Kreskowiak21-Aug-18 9:29
mveDave Kreskowiak21-Aug-18 9:29 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
OriginalGriff21-Aug-18 4:59
mveOriginalGriff21-Aug-18 4:59 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
Member 1204569221-Aug-18 8:30
Member 1204569221-Aug-18 8:30 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
OriginalGriff21-Aug-18 8:38
mveOriginalGriff21-Aug-18 8:38 
GeneralRe: Use custom services inside OAuthorizationProviders Pin
Member 1204569221-Aug-18 20:27
Member 1204569221-Aug-18 20:27 
AnswerRe: Use custom services inside OAuthorizationProviders Pin
Richard Deeming22-Aug-18 2:40
mveRichard Deeming22-Aug-18 2: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 9:32
Ali 2Fan19-Aug-18 9:32 
AnswerRe: help to solve C# codes Pin
OriginalGriff19-Aug-18 9:34
mveOriginalGriff19-Aug-18 9:34 
AnswerRe: help to solve C# codes Pin
Dave Kreskowiak20-Aug-18 10:49
mveDave Kreskowiak20-Aug-18 10:49 
QuestionHow to Merge DataGridView Cell in Winforms ? Pin
Member 245846715-Aug-18 17:32
Member 245846715-Aug-18 17:32 
AnswerRe: How to Merge DataGridView Cell in Winforms ? Pin
dan!sh 16-Aug-18 3:20
professional dan!sh 16-Aug-18 3:20 
QuestionC# add usb device to appxmanifest capabilities for Bosch BNO055 Pin
RAFish040415-Aug-18 8:48
RAFish040415-Aug-18 8:48 
AnswerRe: C# add usb device to appxmanifest capabilities for Bosch BNO055 Pin
Richard Andrew x6415-Aug-18 12:37
professionalRichard Andrew x6415-Aug-18 12:37 
GeneralRe: C# add usb device to appxmanifest capabilities for Bosch BNO055 Pin
RAFish040415-Aug-18 13:41
RAFish040415-Aug-18 13:41 
QuestionWhich language and IDE would require less coding for my test program? Pin
Member 1297423513-Aug-18 15:24
Member 1297423513-Aug-18 15:24 
AnswerRe: Which language and IDE would require less coding for my test program? Pin
OriginalGriff13-Aug-18 19:49
mveOriginalGriff13-Aug-18 19:49 
AnswerRe: Which language and IDE would require less coding for my test program? Pin
Richard MacCutchan13-Aug-18 21:31
mveRichard MacCutchan13-Aug-18 21:31 
AnswerRe: Which language and IDE would require less coding for my test program? Pin
Eddy Vluggen14-Aug-18 0:51
professionalEddy Vluggen14-Aug-18 0:51 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
Mycroft Holmes14-Aug-18 1:30
professionalMycroft Holmes14-Aug-18 1:30 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
Eddy Vluggen14-Aug-18 2:25
professionalEddy Vluggen14-Aug-18 2:25 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
Dave Kreskowiak14-Aug-18 3:30
mveDave Kreskowiak14-Aug-18 3:30 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
OriginalGriff14-Aug-18 3:54
mveOriginalGriff14-Aug-18 3:54 
GeneralRe: Which language and IDE would require less coding for my test program? Pin
Richard MacCutchan14-Aug-18 5:49
mveRichard MacCutchan14-Aug-18 5: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.