locked
Xamarin.Auth StoreCredentials Dependency Injection issue RRS feed

  • Question

  • User250529 posted

    I am trying to save login details, so user doesn't have to reinsert log in details each time he runs app.

    I am trying to use Xamarin.Auth library and AccountStore.

    I've tried to follow this example: https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/general/store-credentials/

    I am wondering how do you differentiate code for Android and iOS in separate classes?

    I found the answer for this here: https://github.com/xamarin/recipes/tree/master/cross-platform/xamarin-forms/General/StoreCredentials

    But this guy puts concrete implementations in separate projects(Android, iOS). How am I suppose to use SimpleIOC or DependencyService to register interfaces to concrete classes if they are in separate projects without doing non-sense cross-reference?

    And how do instances take proper concrete class etc while we try to initiate concrete of interface ICredentialsService?

    Is there better solution like using IF conditions for android and iOS? I cannot create concrete class inside of Portable class since I get error for Forms.Context for example here: var account = AccountStore.Create(Forms.Context).FindAccountsForService(App.AppName).FirstOrDefault(); return (account != null) ? account.Username : null;

    Can you show any working example with SimpleIOC dependency container so I can pass dependency interface through constructor?

    Thursday, August 18, 2016 8:12 PM

Answers

  • User226261 posted

    @AmelSalibasic here you go https://github.com/PubuduGayan/CredentialWallet

    don't forget to mark as answer.. ;)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 18, 2016 9:14 PM

All replies

  • User226261 posted

    @AmelSalibasic here you go https://github.com/PubuduGayan/CredentialWallet

    don't forget to mark as answer.. ;)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 18, 2016 9:14 PM
  • User250529 posted

    PubudGayan how do you check in PCL if credentials exist or not, so you can correctly redirect to correct view?

    Example if you don't use unity with built in dependency:

            var success = DependencyService.Get<ICredentialsService>().DoCredentialsExist();
            if (success)
            {
                return Container.Resolve(typeof(MainPage), "main") as MainPage;
            }
            return Container.Resolve(typeof(LoginPage), "login") as LoginPage;
    
    Friday, August 19, 2016 10:22 AM
  • User226261 posted

    @AmelSalibasic I believe it should be work , I never used built in dependency. If you can create object from interface it should work

    Monday, August 22, 2016 9:40 PM