Note that there are some explanatory texts on larger screens.

plurals
  1. POObjectDisposedException thrown everytime a "User" (membership) object is updated
    primarykey
    data
    text
    <ul> <li>I am using asp.net mvc 3, entity framework with structure map for IoC. </li> <li>I have my own custom membership provider. </li> <li>I had the same kind of problem when I was injecting the dbcontext object and the membership instances using StructureMap so removed this for my UserRepository. </li> <li>The UserRepository now has a DBContext property which is initialised in the constructor.</li> </ul> <p>Everytime a new user is created/updated (the method doing this is wrapping the dbcontext object in using statement), the next time the dbcontext is referenced I get ObjectDisposedException thrown.</p> <p>I don't understand what I am doing wrong. Obviously, the membership provider class isn't instantiating the userRepository object everytime it needs it and when a user is updated, the context is disposed because of the using statement. But I thought this was standard practice?</p> <p>Any help is greatly appreciated.</p> <p>EDITED:</p> <p>There is no complex code really. The set up is:</p> <p>CustomMembershipProvider overrides the standard Membership provider (config file has got the details). CustomMembershipProvider uses IUserService object that uses IUserRepository which is implemented by UserRepository that has the DBContext private object at class level.</p> <p>In the UserRepository, I've got:</p> <pre><code> public void UpdateUser(User user) { using(_db) { ... code to indicate that the user state has changed _db.SaveChanges(); } } </code></pre> <p>Once this code is run, the request is complete. But when another request is made to retrive role information or read the user from the database (in the UserRepository class), I get the ObjectDisposedException thrown. At this point nothing related to User Or Role works because they use the same UserRepository class whose _db variable has been disposed by UpdateUser.</p> <p>I initially had StructureMap resolve the DBContext object, the customMembership object etc but have had to since remove it from StructureMap's mapping.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload