Shazwazza/UmbracoIdentity

Custom user store - results in disposed object

jpiombo opened this issue · 5 comments

Hi, I was reviewing how to extend the User Store class to add lockout features, using this guide:
https://github.com/Shazwazza/UmbracoIdentity/wiki/Startup-Configuration

I have it working implementing the ILockedOut in your code, but was not able to use this with my CustomClass:

public static void ConfigureUserManagerForUmbracoMembers(this IAppBuilder app,
ApplicationContext appContext = null,
IdentityEnabledMembersMembershipProvider membershipProvider = null)
where T : UmbracoIdentityMember, new()

Do you have any more details examples of how to use that method?

Hi, can you provide me more details about what exactly what you have done? The above doesn't contain much information for me to assist with. Thanks.

Hi,
The class i am working with is defined as follows:

image

I am working on implementing the lockout functionality, but i am not sure how to call the method to replace the default implementation:

image

It throws an error with the class being disposed already.

It throws an error with the class being disposed already.

what part of this is throwing an error? what is it saying is disposed already?

I think I've figured out what you mean. I'm pushing a new version and will let you know. The problem is that one owin overload that specifies a user store isn't correct since the manager is a scoped instance that will dispose the store on each request but since this method requires one store it will try to be reused on each request and you'll get the exception that you have.

There's another overload you can use that supplies a <TManager, TUser> with a Func callback and you can create and assign your store in there. This is a work around for now. I'll post back here shortly with an update

I have made the method causing problems obsolete, the method for custom stores will need to use the full call back overload like this:

app.ConfigureUserManagerForUmbracoMembers<UmbracoMembersUserManager<UmbracoApplicationMember>, UmbracoApplicationMember>(
    (options, owinCtx) =>
    {
        // Get the membership provider
        var membershipProvider = Membership.Providers["UmbracoMembershipProvider"] as IdentityEnabledMembersMembershipProvider;

        // Create the user store
        var userStore = new CustomUmbracoMembersUserStore<UmbracoApplicationMember>(
                Current.ProfilingLogger,
                Services.MemberService,
                Services.MemberTypeService,
                Services.MemberGroupService,
                membershipProvider,
                new ExternalLoginStore(Current.ScopeProvider));

        // Create the manager and initialize with default settings
        var manager = UmbracoMembersUserManager<UmbracoApplicationMember>.Create(options, userStore, membershipProvider);

        return manager;
    });

I'll update the docs. Also please have a look at the latest comments here #80