Skip to content

Commit 997c88e

Browse files
Add Copilot instructions for repository guidance (#7)
* Initial plan * Add Copilot instructions for repository guidance Co-authored-by: JohnCampionJr <1094820+JohnCampionJr@users.noreply.github.com> * Update repository structure to include Net6Example and clarify Net9MultiTenant location Co-authored-by: JohnCampionJr <1094820+JohnCampionJr@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JohnCampionJr <1094820+JohnCampionJr@users.noreply.github.com>
1 parent 3cd1ac0 commit 997c88e

1 file changed

Lines changed: 153 additions & 0 deletions

File tree

.github/copilot-instructions.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Copilot Instructions for MongoEntityFramework.AspNetCore.Identity
2+
3+
## Project Overview
4+
5+
This repository provides ASP.NET Core Identity providers for MongoDB.EntityFrameworkCore. It implements the ASP.NET Core Identity system using MongoDB as the backing store via the Entity Framework Core provider.
6+
7+
## Technology Stack
8+
9+
- **Language:** C# (latest LangVersion)
10+
- **Framework:** .NET 8.0 and .NET 9.0 (multi-targeting)
11+
- **Database:** MongoDB (v8.0+)
12+
- **Identity:** ASP.NET Core Identity
13+
- **ORM:** MongoDB.EntityFrameworkCore
14+
- **Testing:** xUnit with AwesomeAssertions
15+
16+
## Repository Structure
17+
18+
```
19+
/src
20+
/MongoFramework.AspNetCore.Identity - Main library source code
21+
- MongoIdentityUser.cs - User entity
22+
- MongoIdentityRole.cs - Role entity
23+
- MongoUserStore.cs - User store implementation
24+
- MongoRoleStore.cs - Role store implementation
25+
- MongoUserOnlyStore.cs - User-only store (no roles)
26+
- MongoIdentityDbContext.cs - DbContext for Identity
27+
- MongoIdentityBuilderExtensions.cs - Service collection extensions
28+
/tests
29+
/MongoFramework.AspNetCore.Identity.Tests - xUnit test project
30+
/examples
31+
/Net6Example - Sample .NET 6.0 web application
32+
/Net9Sample - Sample .NET 9.0 web application
33+
/Net9MultiTenant - Multi-tenant example application (at root, but grouped with examples in .sln)
34+
```
35+
36+
## Build and Test Commands
37+
38+
### Prerequisites
39+
- .NET 8.0 and 9.0 SDKs installed
40+
- MongoDB 8.0+ running locally (required for tests)
41+
42+
### Build
43+
```bash
44+
dotnet restore
45+
dotnet build --no-restore -c Release
46+
```
47+
48+
### Test
49+
```bash
50+
dotnet test --no-restore --no-build --verbosity normal
51+
```
52+
53+
Note: Tests require a running MongoDB instance on the default port (27017).
54+
55+
## Code Standards and Conventions
56+
57+
- **Warnings as Errors:** `TreatWarningsAsErrors` is enabled - all warnings must be resolved
58+
- **CLS Compliance:** Code must be CLS compliant (`CLSCompliant=true`)
59+
- **Language Version:** Uses latest C# language features
60+
- **Multi-targeting:** All library code must support both .NET 8.0 and 9.0
61+
- **Testing:** Uses xUnit and AwesomeAssertions for test assertions
62+
63+
## Key Dependencies
64+
65+
### .NET 9.0
66+
- Microsoft.Extensions.Identity.Core v9.0.10
67+
- Microsoft.Extensions.Identity.Stores v9.0.10
68+
- MongoDB.EntityFrameworkCore v9.0.3
69+
70+
### .NET 8.0
71+
- Microsoft.Extensions.Identity.Core v8.0.21
72+
- Microsoft.Extensions.Identity.Stores v8.0.21
73+
- MongoDB.EntityFrameworkCore v8.3.3
74+
75+
## Architecture Patterns
76+
77+
### Identity Store Implementations
78+
79+
The library implements ASP.NET Core Identity interfaces:
80+
- `IUserStore<TUser>` - Core user storage
81+
- `IRoleStore<TRole>` - Core role storage
82+
- `IUserRoleStore<TUser>` - User-role relationships
83+
- `IUserClaimStore<TUser>` - User claims
84+
- `IUserLoginStore<TUser>` - External logins
85+
- `IUserPasswordStore<TUser>` - Password hashing
86+
- `IUserSecurityStampStore<TUser>` - Security stamps
87+
- And many more Identity-related stores
88+
89+
### Entity Framework Core Integration
90+
91+
- Uses MongoDB.EntityFrameworkCore provider
92+
- DbContext classes: `MongoIdentityDbContext` (with roles), `MongoIdentityUserContext` (users only)
93+
- Entities inherit from Identity base classes and add MongoDB-specific ID handling
94+
95+
### Service Registration
96+
97+
Uses extension methods on `IdentityBuilder`:
98+
```csharp
99+
builder.Services.AddDefaultIdentity<MongoIdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
100+
.AddMongoEntityFrameworkStores<ApplicationDbContext>();
101+
```
102+
103+
## Important Implementation Details
104+
105+
1. **Identity Specification Tests**: The project includes ASP.NET Core's Identity specification tests (IdentitySpecificationBase) to ensure compliance with the Identity contract.
106+
107+
2. **Check Class**: Uses a `Check` utility class for argument validation - prefer this over manual null checks.
108+
109+
3. **MongoDB ID Handling**: Entities use `ObjectId` from MongoDB.Bson for primary keys.
110+
111+
4. **Async Patterns**: All store methods follow async/await patterns with proper cancellation token support.
112+
113+
## Common Tasks
114+
115+
### Adding a New Store Method
116+
1. Implement the interface method in the appropriate store class (`MongoUserStore`, `MongoRoleStore`, etc.)
117+
2. Use Entity Framework Core patterns for data access
118+
3. Add corresponding unit tests in the tests project
119+
4. Ensure cancellation token is properly threaded through
120+
5. Include appropriate null checks using the `Check` class
121+
122+
### Updating Dependencies
123+
- Dependencies are version-specific per target framework (net8.0 vs net9.0)
124+
- Update both framework conditions in .csproj files
125+
- Ensure compatibility with both MongoDB.EntityFrameworkCore versions
126+
127+
### Adding Tests
128+
- Place tests in appropriate subdirectories under `tests/MongoFramework.AspNetCore.Identity.Tests/`
129+
- Group related tests in subdirectories (e.g., `MongoUserStoreTests/`)
130+
- Use AwesomeAssertions for more readable assertions
131+
- Follow existing test naming patterns
132+
133+
## CI/CD
134+
135+
- **Testing:** GitHub Actions runs tests on Ubuntu with MongoDB 8.0
136+
- **Publishing:** Automated NuGet package publishing via release-please
137+
- **Multi-targeting:** Tests run against both .NET 8.0 and 9.0
138+
139+
## Package Information
140+
141+
- **Package ID:** jcamp.MongoEntityFramework.AspNetCore.Identity
142+
- **License:** MIT
143+
- **Author:** John Campion
144+
- **Tags:** mongodb, mongoframework, mongo, identity
145+
146+
## When Making Changes
147+
148+
1. Ensure changes work for both .NET 8.0 and 9.0 target frameworks
149+
2. Run all tests before committing (`dotnet test`)
150+
3. Maintain backward compatibility where possible
151+
4. Update XML documentation comments for public APIs
152+
5. Follow existing patterns in the codebase
153+
6. Consider if Identity specification tests need updates

0 commit comments

Comments
 (0)