Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions SampleWebApp.Core.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApp.Core", "SampleWebApp.Core\SampleWebApp.Core.csproj", "{D1A1C7B1-1111-4111-8111-111111111111}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Core", "Tests.Core\Tests.Core.csproj", "{D1A1C7B2-2222-4222-8222-222222222222}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D1A1C7B1-1111-4111-8111-111111111111}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1A1C7B1-1111-4111-8111-111111111111}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1A1C7B1-1111-4111-8111-111111111111}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1A1C7B1-1111-4111-8111-111111111111}.Release|Any CPU.Build.0 = Release|Any CPU
{D1A1C7B2-2222-4222-8222-222222222222}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1A1C7B2-2222-4222-8222-222222222222}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1A1C7B2-2222-4222-8222-222222222222}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1A1C7B2-2222-4222-8222-222222222222}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
35 changes: 35 additions & 0 deletions SampleWebApp.Core/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc;
using SampleWebApp.Core.Models;

namespace SampleWebApp.Core.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}

public IActionResult About()
{
ViewBag.Message = "Your application description page.";

return View();
}

public IActionResult Contact()
{
return View();
}

public IActionResult Internals()
{
return View(new InternalsInfo());
}

public IActionResult CodeView()
{
return View();
}
}
}
30 changes: 30 additions & 0 deletions SampleWebApp.Core/Models/InternalsInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Threading;

namespace SampleWebApp.Core.Models
{
public class InternalsInfo
{
public int WorkerThreads { get; private set; }

public int AvailableThreads { get; private set; }

public int AvailableMbytes { get; private set; }

public int HeapMemoryUsedKbytes { get; private set; }

public InternalsInfo()
{
ThreadPool.GetMaxThreads(out int workerThreads, out _);
ThreadPool.GetAvailableThreads(out int availableThreads, out _);

WorkerThreads = workerThreads;
AvailableThreads = availableThreads;

var gcInfo = GC.GetGCMemoryInfo();
AvailableMbytes = (int)(gcInfo.TotalAvailableMemoryBytes / (1024L * 1024L));

HeapMemoryUsedKbytes = (int)(GC.GetTotalMemory(false) / 1000);
}
}
}
24 changes: 24 additions & 0 deletions SampleWebApp.Core/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllersWithViews();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

public partial class Program { }
29 changes: 29 additions & 0 deletions SampleWebApp.Core/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5000",
"sslPort": 0
}
},
"profiles": {
"SampleWebApp.Core": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
11 changes: 11 additions & 0 deletions SampleWebApp.Core/SampleWebApp.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>SampleWebApp.Core</RootNamespace>
<AssemblyName>SampleWebApp.Core</AssemblyName>
</PropertyGroup>

</Project>
65 changes: 65 additions & 0 deletions SampleWebApp.Core/Views/Home/About.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@{
ViewBag.Title = "About";
}
<h2>About this site</h2>

<h3>About this site</h3>
<p>
You should have seen on the @Html.ActionLink("Home Page", "Index") a brief introduction to the site.
The site is here as a testing bed/demonstration of the <a href="https://github.com/JonPSmith/GenericServices" target="_blank">GenericServices library</a>
and a number of software patterns specific to ASP.NET MVC. All the work here is open source under the
<a href="http://opensource.org/licenses/MIT" target="_blank">MIT licence</a>.
</p>
<p>
The @Html.ActionLink("Introduction to GenericServices", "CodeView") page goes into more detail about GenericServices library and some of the
items demonstrated on this web site. I also suggest you look at GenericServices's
<a href="https://github.com/JonPSmith/GenericServices/blob/master/README.md" target="_blank">read.me</a> file which gives more information.
</p>

<h3>Documentation</h3>
<ul>
<li>
The <a href="https://github.com/JonPSmith/GenericServices/wiki" target="_blank">GenericServices Wiki</a>
now contains comprehensive documentation on GenericServices.
</li>
<li>A new, more complex example is now available at <a href="http://complex.samplemvcwebapp.net/">Complex.SampleMvcWebApp</a>.</li>
</ul>

<h3>Related articles</h3>
<p>
I have written a number of articles/blog posts which relate to this site. They are:
</p>
<ul>
<li>
<a href="http://www.thereformedprogrammer.net/alpha-release-of-genericservices/" target="_blank">
Alpha release of GenericServices
</a> on my own blog site.
</li>
<li>
<a href="https://www.simple-talk.com/dotnet/.net-framework/catching-bad-data-in-entity-framework/" target="_blank">
Catching Bad Data in Entity Framework
</a> on Simple Talk site.
</li>
<li>
<a href="https://www.simple-talk.com/dotnet/.net-framework/the-.net-4.5-asyncawait-commands-in-promise-and-practice/" target="_blank">
The performance of async/await in Entity Framework 6 and ASP.NET MVC5
</a> on Simple Talk site.
</li>
<li>
<a href="https://www.simple-talk.com/dotnet/.net-framework/using-entity-framework-with-an-existing-database-data-access/" target="_blank">
Using Entity Framework With an Existing Database: Data Access
</a> on Simple Talk site
</li>
<li>
<a href="https://www.simple-talk.com/dotnet/asp.net/using-entity-framework-with-an-existing-database--user-interface/" target="_blank">
Using Entity Framework with an Existing Database: User Interface
</a> on Simple Talk site.
</li>
</ul>
<p>
The last article in particular provides a good architectural overview of a MVC web site built Entity Framework and GenericServices.
</p>
<br />
<p>
@Html.ActionLink("Back to Home", "Index")
</p>
38 changes: 38 additions & 0 deletions SampleWebApp.Core/Views/Home/CodeView.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@{
ViewBag.Title = "CodeView";
}
<h2>Introduction to GenericServices</h2>
<p>
GenericServices is a .NET class library which helps a developer build a
<a href="http://martinfowler.com/eaaCatalog/serviceLayer.html" target="_blank">service layer</a>,
i.e. a layer that acts as a facard/adapter between your business/data service layers and your User Interface or HTTP service.

It does this by providing standard database CRUD (Create, Read, Update and Delete) methods and a standard way of
calling business methods, each with clear extension points.
The aim is to cut out the standard boiler-plate code so the user only has to write the data or business specific code.
</p>
<p>
Some ASP.NET MVC specific features which build on the GenericService are also included.
For instance the best way to call GenericService commands in a Controller and handling long-running tasks.
</p>
<hr />
<h3>Summary of the features covered by this example web site</h3>

<h4>1. Simple, but robust database services</h4>
<p>
Database accesses are normally a big part of enterprise systems build with APS.NET MVC. However, my experience is that creating these services
in a robust and comprehensive form can lead to a lot of repetative code that does the same thing, but for different data.
The aim of the GenericFramework framework is to handles all of the standard cases, and include extension points for when special handling is required.
Examples of there use on this web site are:
</p>
<ul>
<li>See normal, synchronous access using a <abbr title="Data Transfer Object">DTO</abbr> for shaping in the @Html.ActionLink("Posts", "Index", "Posts") Controller</li>
<li>See new EF6 async access using a <abbr title="Data Transfer Object">DTO</abbr> for shaping in the @Html.ActionLink("PostsAsync", "Index", "PostsAsync") Controller</li>
<li>See normal, synchronous access directly via data class in the @Html.ActionLink("Tags", "Index", "Tags") Controller</li>
<li>See new EF6 async access directly via data class in the @Html.ActionLink("TagsAsync", "Index", "TagsAsync") Controller</li>
</ul>

<p>
Note that the SampleMvcWebApp uses <a href="https://github.com/autofac/Autofac/wiki/Getting-Started" target="_blank">AutoFac</a>
dependency injection framework to insert calls to the various GenericServices services.
</p>
19 changes: 19 additions & 0 deletions SampleWebApp.Core/Views/Home/Contact.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@{
ViewBag.Title = "Contact";
}
<h2>Contact</h2>
<h3>About the Author</h3>
<p>
The author of this open-source project is Jon Smith.
You may also be interested in my technical blog, <a href="http://www.thereformedprogrammer.net/" target="_blank">www.thereformedprogrammer.net</a>.
The site <a href="http://selectiveanalytics.com/" target="_blank">Selective Analytics</a> shows some of the analytical work I have done with my wife,
Dr Honora Smith.
</p>
<p>
You can find out more about me via my <a href="http://uk.linkedin.com/pub/jon-smith/0/327/97a">LinkedIn page</a>
or my <a href="http://www.thereformedprogrammer.net/about-me/" target="_blank">about me</a> page on my blog site.
</p>
<p>
You can contact me through my <a href="http://www.thereformedprogrammer.net/">Technical Blog Site</a>.
I am available for short to medium term contracts as both a software architect and developer.
</p>
79 changes: 79 additions & 0 deletions SampleWebApp.Core/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@{
ViewBag.Title = "Index";
}

<h2>Welcome to the Sample MVC Web Application - basic version</h2>

<p>
<strong>
This web site is designed as a basic interoduction to GenericServices Framework's CRUD commands
by showing them working in an ASP.NET MVC web site.
The <a href="https://github.com/JonPSmith/GenericServices" target="_blank">GenericServices library</a>
and this <a href="https://github.com/JonPSmith/SampleMvcWebApp" target="_blank">example web site</a>
are both open source projects by
<a href="http://www.thereformedprogrammer.net/about-me/" target="_blank">Jon Smith</a> under the
<a href="http://opensource.org/licenses/MIT" target="_blank">MIT licence</a>.
</strong>
</p>
<h2>UPDATE for 2015</h2>
<ul>
<li>
<h4>
GenericService is now available on Nuget - see <a href="https://www.nuget.org/packages/GenericServices/" target="_blank">GenericServices on NuGet</a>.
</h4>
</li>
<li>
<h4>
A new, more complex example is now available at <a href="http://complex.samplemvcwebapp.net/">Complex.SampleMvcWebApp</a>.
</h4>
</li>
<li>
<h4>
The <a href="https://github.com/JonPSmith/GenericServices/wiki" target="_blank">GenericServices Wiki</a>
now contains comprehensive documentation on GenericServices.
</h4>
</li>
</ul>

<h3 class="text-info">Where should I start?</h3>
<ul>
<li>You dive right in by clicking one of the menu links at the top of this page. Try Sync database -> @Html.ActionLink("Posts", "Index", "Posts") as a start.</li>
<li>Go to @Html.ActionLink("this page", "CodeView") for more detail on what code features are shown on this site.</li>
<li>
You can look at the the GenericServices's <a href="https://github.com/JonPSmith/GenericServices/blob/master/README.md" target="_blank">read.me</a> file
or SampleMvcWebApp's <a href="https://github.com/JonPSmith/SampleMvcWebApp/blob/master/README.md" target="_blank">read.me</a> file on GitHub.
</li>
</ul>

<hr />
<h3>Some notes about what this site is, and is not</h3>

<h3 class="text-info">This site is about programming, not styling</h3>
<h4 class="text-muted">
The site introduces the GenericServices Framework for back-end development.
</h4>
<p>
As much as possible the site uses the standard MVC5 BootStrap style and templates, because the main emphasis is on the back-end code. <br />
I have made the styling as basic as possible, which should make it easier for you to restyle it the way you want it.
</p>
<small>Of course I have tried to stop it looking ugly. You can decide whether I succeeded.</small>

<h3 class="text-info">The pages are examples, not solutions</h3>
<h4 class="text-muted">
The site demos framework commands. The data is irrelevant.
</h4>
<p>
The aim is to show how you can use the GenericServices commands to manipulate data. <br />
I have used fictitious, but credible data classes to do this. Some of the data validation rules are a somewhat bizarre to make a point.
</p>
<small>I have tried to make the data interesting. Enjoy.</small>

<h3 class="text-info">The pages contain explanations</h3>
<h4 class="text-muted">
As well as showing the framework in action it includes links to explanations of the code.
</h4>
<p>
On most pages you will see a @Html.ActionLink("Explanation of the code", "CodeView") link. It is normally on the right hand side above the data.<br />
This takes you to a page that a) has links to the actual source on GitHub and b) tries to explain how it all hangs together.
</p>
<small>Remember, the links to the code on GitHub are always the best documentation.</small>
Loading