Top Related Projects
Documentation for ASP.NET Core
ASP.NET Boilerplate - Web Application Framework
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
Quick Overview
ContosoUniversityDotNetCore-Pages is a sample application demonstrating ASP.NET Core Razor Pages with Entity Framework Core in .NET Core. It's based on the original Contoso University sample but updated to use Razor Pages instead of MVC, showcasing modern ASP.NET Core development practices.
Pros
- Demonstrates best practices for ASP.NET Core Razor Pages development
- Includes examples of Entity Framework Core usage and database operations
- Provides a realistic scenario (university management) for learning purposes
- Regularly updated to reflect the latest .NET Core versions and features
Cons
- May be overwhelming for absolute beginners due to its complexity
- Focuses primarily on Razor Pages, which might not be suitable for those seeking MVC examples
- Limited coverage of advanced topics like authentication and authorization
- Some parts of the codebase might become outdated as .NET Core evolves rapidly
Code Examples
- Creating a new student (from Pages/Students/Create.cshtml.cs):
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
var emptyStudent = new Student();
if (await TryUpdateModelAsync<Student>(
emptyStudent,
"student", // Prefix for form value.
s => s.FirstMidName, s => s.LastName, s => s.EnrollmentDate))
{
_context.Students.Add(emptyStudent);
await _context.SaveChangesAsync();
return RedirectToPage("./Index");
}
return Page();
}
- Querying and displaying a list of courses (from Pages/Courses/Index.cshtml.cs):
public async Task OnGetAsync()
{
IQueryable<Course> coursesIQ = from c in _context.Courses
select c;
if (!string.IsNullOrEmpty(SearchString))
{
coursesIQ = coursesIQ.Where(s => s.Title.Contains(SearchString));
}
if (SelectedDepartment.HasValue)
{
coursesIQ = coursesIQ.Where(x => x.DepartmentID == SelectedDepartment);
}
Courses = await coursesIQ.AsNoTracking().ToListAsync();
}
- Configuring Entity Framework Core (from Data/SchoolContext.cs):
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Course>().ToTable("Course");
modelBuilder.Entity<Enrollment>().ToTable("Enrollment");
modelBuilder.Entity<Student>().ToTable("Student");
modelBuilder.Entity<Department>().ToTable("Department");
modelBuilder.Entity<Instructor>().ToTable("Instructor");
modelBuilder.Entity<OfficeAssignment>().ToTable("OfficeAssignment");
modelBuilder.Entity<CourseAssignment>().ToTable("CourseAssignment");
modelBuilder.Entity<CourseAssignment>()
.HasKey(c => new { c.CourseID, c.InstructorID });
}
Getting Started
-
Clone the repository:
git clone https://github.com/jbogard/ContosoUniversityDotNetCore-Pages.git
-
Navigate to the project directory:
cd ContosoUniversityDotNetCore-Pages
-
Restore dependencies and run the application:
dotnet restore dotnet run
-
Open a web browser and navigate to
http://localhost:5000
to view the application.
Competitor Comparisons
Documentation for ASP.NET Core
Pros of AspNetCore.Docs
- Comprehensive documentation covering a wide range of ASP.NET Core topics
- Regularly updated with the latest features and best practices
- Includes code samples and tutorials for various scenarios
Cons of AspNetCore.Docs
- Focuses on documentation rather than a complete, runnable application
- May be overwhelming for beginners due to the breadth of information
- Less emphasis on real-world application architecture
Code Comparison
AspNetCore.Docs (Middleware example):
app.Use(async (context, next) =>
{
// Do work that doesn't write to the Response.
await next.Invoke();
// Do logging or other work that doesn't write to the Response.
});
ContosoUniversityDotNetCore-Pages (Page model example):
public async Task<IActionResult> OnGetAsync(int? id)
{
if (id == null)
{
return NotFound();
}
Student = await _context.Students.FirstOrDefaultAsync(m => m.ID == id);
if (Student == null)
{
return NotFound();
}
return Page();
}
The AspNetCore.Docs repository provides more general-purpose code snippets, while ContosoUniversityDotNetCore-Pages offers complete, context-specific implementations within a functional application.
ASP.NET Boilerplate - Web Application Framework
Pros of aspnetboilerplate
- Comprehensive framework with built-in modules for common enterprise application features
- Multi-tenancy support out of the box
- Extensive documentation and community support
Cons of aspnetboilerplate
- Steeper learning curve due to its complexity and extensive features
- Potentially overkill for smaller projects or simple applications
- More opinionated architecture, which may limit flexibility in some cases
Code Comparison
ContosoUniversityDotNetCore-Pages:
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
}
aspnetboilerplate:
public class Person : FullAuditedEntity<long>
{
public virtual string Name { get; set; }
public virtual string Surname { get; set; }
public virtual string EmailAddress { get; set; }
}
The code comparison shows that aspnetboilerplate uses a more complex entity structure with built-in auditing features, while ContosoUniversityDotNetCore-Pages uses simpler POCO classes. This reflects the difference in complexity and feature set between the two projects.
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
Pros of ABP
- Comprehensive framework with built-in modules for common functionalities
- Supports multi-tenancy out of the box
- Extensive documentation and community support
Cons of ABP
- Steeper learning curve due to its complexity
- May be overkill for smaller projects
- Less flexibility in architectural decisions
Code Comparison
ContosoUniversityDotNetCore-Pages:
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
}
ABP:
public class Student : FullAuditedAggregateRoot<Guid>
{
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
protected Student() { }
public Student(Guid id, string lastName, string firstMidName, DateTime enrollmentDate) : base(id)
{
LastName = lastName;
FirstMidName = firstMidName;
EnrollmentDate = enrollmentDate;
}
}
The ABP framework provides more built-in functionality in its base classes, such as auditing and GUID-based IDs, while ContosoUniversityDotNetCore-Pages uses a simpler approach with basic properties and integer IDs.
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
Pros of CleanArchitecture
- Implements a more robust and scalable architecture, following Clean Architecture principles
- Provides a clear separation of concerns with distinct layers (Core, Infrastructure, Web)
- Includes more advanced features like CQRS pattern and MediatR for handling requests
Cons of CleanArchitecture
- More complex structure, which may be overkill for smaller projects
- Steeper learning curve for developers unfamiliar with Clean Architecture concepts
- Requires more initial setup and boilerplate code
Code Comparison
CleanArchitecture:
public class DeleteTodoItemCommand : IRequest
{
public int Id { get; set; }
}
public class DeleteTodoItemCommandHandler : IRequestHandler<DeleteTodoItemCommand>
{
private readonly IApplicationDbContext _context;
public DeleteTodoItemCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteTodoItemCommand request, CancellationToken cancellationToken)
{
var entity = await _context.TodoItems.FindAsync(request.Id);
if (entity == null)
{
throw new NotFoundException(nameof(TodoItem), request.Id);
}
_context.TodoItems.Remove(entity);
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
ContosoUniversityDotNetCore-Pages:
public async Task<IActionResult> OnPostAsync(int? id)
{
if (id == null)
{
return NotFound();
}
var course = await _context.Courses.FindAsync(id);
if (course != null)
{
Course = course;
await _context.Courses.RemoveAsync(Course);
await _context.SaveChangesAsync();
}
return RedirectToPage("./Index");
}
ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
Pros of nopCommerce
- Full-featured e-commerce platform with extensive functionality
- Active community and regular updates
- Highly customizable with plugin architecture
Cons of nopCommerce
- More complex and larger codebase
- Steeper learning curve for beginners
- May be overkill for simple projects
Code Comparison
nopCommerce (Product.cs):
public partial class Product : BaseEntity, ILocalizedEntity, ISlugSupported, IDiscountSupported<DiscountProductMapping>, IAclSupported, IStoreMappingSupported
{
public string Name { get; set; }
public string ShortDescription { get; set; }
public string FullDescription { get; set; }
public string AdminComment { get; set; }
public int ProductTypeId { get; set; }
}
ContosoUniversityDotNetCore-Pages (Student.cs):
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
}
The nopCommerce code shows a more complex entity with multiple interfaces and additional properties, reflecting its comprehensive e-commerce features. ContosoUniversityDotNetCore-Pages has a simpler model, focused on educational domain concepts.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ContosoUniversity on ASP.NET Core 6.0 on .NET 6 and Razor Pages
Contoso University, the way I would write it.
This example requires some tools and PowerShell modules, you should run setup.cmd
or setup.ps1
to install them.
To prepare the database, execute the build script using PSake: psake migrate
. Open the solution and run!
Things demonstrated
- CQRS and MediatR
- AutoMapper
- Vertical slice architecture
- Razor Pages
- Fluent Validation
- HtmlTags
- Entity Framework Core
Migrating the Database
Grate will automatically create or upgrade (migrate) the database to the latest schema version when you run it:
From PowerShell:
invoke-psake migrate
From CMD:
psake migrate
When running unit tests, you can recreate the unit test database using:
invoke-psake migratetest
Versioning
Version numbers can be passed on the build script command line:
From PowerShell:
invoke-psake CI -properties ${'version':'1.2.3-dev.5'}
Because we're passing a PowerShell dictionary on the command line, the cmd script doesn't handle this very nicely.
Or generate a version using GitVersion locally:
psake localversion
will generate a semantic version and output it.
Top Related Projects
Documentation for ASP.NET Core
ASP.NET Boilerplate - Web Application Framework
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot