{"action":"created","issue":{"url":"https://api.github.com/repos/zzzprojects/EntityFramework-Plus/issues/163","repository_url":"https://api.github.com/repos/zzzprojects/EntityFramework-Plus","labels_url":"https://api.github.com/repos/zzzprojects/EntityFramework-Plus/issues/163/labels{/name}","comments_url":"https://api.github.com/repos/zzzprojects/EntityFramework-Plus/issues/163/comments","events_url":"https://api.github.com/repos/zzzprojects/EntityFramework-Plus/issues/163/events","html_url":"https://github.com/zzzprojects/EntityFramework-Plus/issues/163","id":230521068,"number":163,"title":"Problem with multiple DbContext and AutoSavePreAction","user":{"login":"drodic","id":19417039,"avatar_url":"https://avatars2.githubusercontent.com/u/19417039?v=3","gravatar_id":"","url":"https://api.github.com/users/drodic","html_url":"https://github.com/drodic","followers_url":"https://api.github.com/users/drodic/followers","following_url":"https://api.github.com/users/drodic/following{/other_user}","gists_url":"https://api.github.com/users/drodic/gists{/gist_id}","starred_url":"https://api.github.com/users/drodic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drodic/subscriptions","organizations_url":"https://api.github.com/users/drodic/orgs","repos_url":"https://api.github.com/users/drodic/repos","events_url":"https://api.github.com/users/drodic/events{/privacy}","received_events_url":"https://api.github.com/users/drodic/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"JonathanMagnan","id":23240780,"avatar_url":"https://avatars3.githubusercontent.com/u/23240780?v=3","gravatar_id":"","url":"https://api.github.com/users/JonathanMagnan","html_url":"https://github.com/JonathanMagnan","followers_url":"https://api.github.com/users/JonathanMagnan/followers","following_url":"https://api.github.com/users/JonathanMagnan/following{/other_user}","gists_url":"https://api.github.com/users/JonathanMagnan/gists{/gist_id}","starred_url":"https://api.github.com/users/JonathanMagnan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonathanMagnan/subscriptions","organizations_url":"https://api.github.com/users/JonathanMagnan/orgs","repos_url":"https://api.github.com/users/JonathanMagnan/repos","events_url":"https://api.github.com/users/JonathanMagnan/events{/privacy}","received_events_url":"https://api.github.com/users/JonathanMagnan/received_events","type":"User","site_admin":false},"assignees":[{"login":"JonathanMagnan","id":23240780,"avatar_url":"https://avatars3.githubusercontent.com/u/23240780?v=3","gravatar_id":"","url":"https://api.github.com/users/JonathanMagnan","html_url":"https://github.com/JonathanMagnan","followers_url":"https://api.github.com/users/JonathanMagnan/followers","following_url":"https://api.github.com/users/JonathanMagnan/following{/other_user}","gists_url":"https://api.github.com/users/JonathanMagnan/gists{/gist_id}","starred_url":"https://api.github.com/users/JonathanMagnan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonathanMagnan/subscriptions","organizations_url":"https://api.github.com/users/JonathanMagnan/orgs","repos_url":"https://api.github.com/users/JonathanMagnan/repos","events_url":"https://api.github.com/users/JonathanMagnan/events{/privacy}","received_events_url":"https://api.github.com/users/JonathanMagnan/received_events","type":"User","site_admin":false}],"milestone":null,"comments":1,"created_at":"2017-05-22T21:12:17Z","updated_at":"2017-05-23T18:59:26Z","closed_at":"2017-05-23T18:59:26Z","body":"I passing two DbContexts in manager constructor responsible for business logic as interface, and in those DbContexts constructors I put this code:\r\n`// Globally\r\n            AuditManager.DefaultConfiguration.AutoSavePreAction = (context, audit) =>\r\n                (context as BeeGoDbContext).AuditEntries.AddRange(audit.Entries);`\r\nand:\r\n`            // Globally\r\n            AuditManager.DefaultConfiguration.AutoSavePreAction = (context, audit) =>\r\n                (context as AcctDbContext).AuditEntries.AddRange(audit.Entries);`\r\n\r\nOnly settings for last resolved DbContext is set and I'm get error for second one. This is probably because this AuditManager is static class and because of that it has only one instance.\r\nIs it posible to configure AutoSavePreAction for this case?"},"comment":{"url":"https://api.github.com/repos/zzzprojects/EntityFramework-Plus/issues/comments/303498867","html_url":"https://github.com/zzzprojects/EntityFramework-Plus/issues/163#issuecomment-303498867","issue_url":"https://api.github.com/repos/zzzprojects/EntityFramework-Plus/issues/163","id":303498867,"user":{"login":"drodic","id":19417039,"avatar_url":"https://avatars2.githubusercontent.com/u/19417039?v=3","gravatar_id":"","url":"https://api.github.com/users/drodic","html_url":"https://github.com/drodic","followers_url":"https://api.github.com/users/drodic/followers","following_url":"https://api.github.com/users/drodic/following{/other_user}","gists_url":"https://api.github.com/users/drodic/gists{/gist_id}","starred_url":"https://api.github.com/users/drodic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drodic/subscriptions","organizations_url":"https://api.github.com/users/drodic/orgs","repos_url":"https://api.github.com/users/drodic/repos","events_url":"https://api.github.com/users/drodic/events{/privacy}","received_events_url":"https://api.github.com/users/drodic/received_events","type":"User","site_admin":false},"created_at":"2017-05-23T18:59:26Z","updated_at":"2017-05-23T18:59:26Z","body":"Hi Jonathan,\r\n\r\nI figured out how to solve this problem. Thank you for example but I have those DbContext in separate assemblies and I don't want to include one assembly in the other assembly.\r\nFinally, I decided to remove AutoSavePreAction and manually add Audit entries in SaveChangesAsync method.\r\nSo, I replaced this code:\r\n```            \r\nif (audit.Configuration.AutoSavePreAction != null) \r\n{\r\n     audit.Configuration.AutoSavePreAction(this, audit);\r\n     await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);\r\n}\r\n```\r\nwith this code:\r\n```\r\nawait AuditEntries.AddRangeAsync(audit.Entries);\r\nawait base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);\r\n```\r\nAnd in the end, thank you for this great library :)"}}
{"actor":{"display_login":"drodic"}}