Note that there are some explanatory texts on larger screens.

plurals
  1. POWindsor 'Scope cache was already disposed' within Envers custom Revision Listener
    primarykey
    data
    text
    <p><strong>Update</strong>: I think is down to a <strong>Windsor configuration</strong>, does any one have any idea as to what I have not configured correctly with Windsor?</p> <p>I am currently using Envers within a C# WebApi project. Windsor is used for IoC. I have a custom RevisionEntity which add a User property to audit the user who has made the data change.</p> <p>To ensure all configurations were correct I started off with a "simple string here" being added in the NewRevision method;</p> <pre><code>public class AuditRevisionListener : IRevisionListener { public void NewRevision(object revisionEntity) { ((AuditRevision)revisionEntity).User = "Simple string here"; } } </code></pre> <p>and all persisted as expected.</p> <p>Next step is to achieve a full User object to which I need to obtain the UserService;</p> <pre><code>public class AuditRevisionListener : IRevisionListener { public void NewRevision(object revisionEntity) { var userServices = (IUserServices)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IUserServices)); var user = userServices.GetRequestingUser(); ((AuditRevision)revisionEntity).User = user; } } </code></pre> <p>However, the DependencyResolver.GetService is throwing the error; "<strong>Cannot access a disposed object. Object name: 'Scope cache was already disposed. This is most likely a bug in the calling code.</strong>'. "</p> <p><strong>UPDATE</strong> I have now created a demo project available at <a href="https://github.com/ScottFindlater/WindsorEnversIssue" rel="nofollow">https://github.com/ScottFindlater/WindsorEnversIssue</a> </p> <p>On first setting up the solution all will run fine because the custom Envers RevisionListener is <strong>not</strong> performing any dependency resolving. </p> <p>Run the solution which performs a GET to the HomeController, which simply loads one User and modifies another;</p> <ul> <li>Dependency resolving is shown to be working as there is an ActionFilter called DependencyResolverDoesWork which successfully resolves the UserServices. </li> <li>Envers is shown to be working as the UserAudit table is populated.</li> </ul> <p>To “turn on” the dependency resolving in the customer RevisionListener navigate to; Domain NHibernate project, Auditing folder, AuditRevisionListener class, NewRevision method and uncomment the 2 lines of code.</p> <p>Full rebuild and then run the solution again and the project will run time exception in the WindsorDependencyResolver class, GetService method with “<strong>Cannot access a disposed object</strong>”, and clicking the View Detail Action expands this message to “{"<strong>Cannot access a disposed object.\r\nObject name: 'Scope cache was already disposed. This is most likely a bug in the calling code.</strong>'."}”.</p> <p>The comment posted by Roger, thank you so much, which suggests changing the LifeStyle to Singleton does work. However, this demo has been purposefully kept simple and the use of PerWebRequest LifeStyle is needed because the ApplicationServices in the real project has contextual related data injected such as requesting user which is used to enforce security. </p> <p>I am so stuck now and any pointers/ answers as to what I have setup wrong will be gratefully received. In addition, I know this has been posted at SO and Envers forum, I WILL update an answer on both.</p> <p>I think is down to a Windsor configuration, does any one have any idea as to what I have not configured correctly with Windsor?</p>
    singulars
    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.
 

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