Conversation
|
@sagilio please review |
|
|
…with DI Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
…mples Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
|
@VictorioBerra plz review |
I think this looks good. I would recommend updating https://github.com/casbin-net/casbin-aspnetcore/tree/master/samples/WebApplicationWithEfcoreSample as well once this is shipped to use the new extension methods. I liked |
@copilot modify based on the above comment |
I'm working in the efcore-adapter repository and don't have access to modify the casbin-aspnetcore repository. The sample update would need to be done separately in that repository once this PR is merged and the new version is published to NuGet. All the changes needed for this fix are complete in this PR:
The casbin-aspnetcore sample can be updated by the maintainers after this is released. |
|
🎉 This PR is included in version 2.10.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
- Add ServiceProviderContextProvider to wrap IServiceProvider in ICasbinDbContextProvider - Support three constructor modes: direct context, DI context, and multi-context provider - Maintain full backward compatibility with both existing patterns - Unify internal architecture around ICasbinDbContextProvider - Add IServiceProvider constructor to all adapter wrapper classes Resolves conflict between upstream PR apache#89 (IServiceProvider support) and multi-context feature by supporting both patterns through unified provider interface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Update README.md: Merge upstream DI section with multi-context support section * Keep IServiceProvider documentation from PR apache#89 (single-context DI) * Add multi-context section with quick example and transaction warnings * Document all 3 supported modes: direct, DI single-context, multi-context * Add links to detailed documentation files - Add MULTI_CONTEXT_DESIGN.md (636 lines): * Architecture and design decisions * Provider pattern explanation * Transaction coordination mechanisms * Performance considerations (ExecuteDelete, DbSet caching) * Database limitations and requirements - Add MULTI_CONTEXT_USAGE_GUIDE.md (585 lines): * Step-by-step usage guide with complete examples * Schema v0-v13 upgrade requirements * EnableAutoSave behavior and transaction atomicity * Connection sharing requirements * Common pitfalls and troubleshooting Documentation covers: - How to use multi-context with manually created contexts - Transaction integrity requirements (shared connection, AutoSave off) - Schema distribution patterns - Integration test setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…d long-lived services (apache#89)
- Add ServiceProviderContextProvider to wrap IServiceProvider in ICasbinDbContextProvider - Support three constructor modes: direct context, DI context, and multi-context provider - Maintain full backward compatibility with both existing patterns - Unify internal architecture around ICasbinDbContextProvider - Add IServiceProvider constructor to all adapter wrapper classes Resolves conflict between upstream PR apache#89 (IServiceProvider support) and multi-context feature by supporting both patterns through unified provider interface.
- Update README.md: Merge upstream DI section with multi-context support section * Keep IServiceProvider documentation from PR apache#89 (single-context DI) * Add multi-context section with quick example and transaction warnings * Document all 3 supported modes: direct, DI single-context, multi-context * Add links to detailed documentation files - Add MULTI_CONTEXT_DESIGN.md (636 lines): * Architecture and design decisions * Provider pattern explanation * Transaction coordination mechanisms * Performance considerations (ExecuteDelete, DbSet caching) * Database limitations and requirements - Add MULTI_CONTEXT_USAGE_GUIDE.md (585 lines): * Step-by-step usage guide with complete examples * Schema v0-v13 upgrade requirements * EnableAutoSave behavior and transaction atomicity * Connection sharing requirements * Common pitfalls and troubleshooting Documentation covers: - How to use multi-context with manually created contexts - Transaction integrity requirements (shared connection, AutoSave off) - Schema distribution patterns - Integration test setup
When using EFCoreAdapter with dependency injection (e.g., casbin-aspnetcore), the adapter stores a direct reference to a scoped DbContext. When the scope ends, the DbContext is disposed but the long-lived Enforcer continues using the adapter, causing
ObjectDisposedExceptionon subsequent policy operations.Changes
Added IServiceProvider-based constructor
GetOrResolveDbContext()to obtain fresh instancesAdded DI registration extension methods
AddEFCoreAdapter<TKey>()andAddEFCoreAdapter<TKey, TPersistPolicy>()Added tests
Usage
Resolves #[issue_number]
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.