Asp.Net MVC Solution Architecture project with Async Repository pattern by Service having Dependency Injection by Unity - Page 1
Introduction
Asp.Net MVC Solution Architecture project presents a flexible layered architecture is inspired from some of the best solutions structure's available incorporating the best practices like Async Repository Pattern, Dependency Injection in ASP.NET MVC using Unity IoC Container, Entity Framework, POCO classes and Application Service layer for BAL.
It re-uses the Entity models in various layers. At the same time other View Models for UI and Business Models can be introduced as when required for complex operations.
Background
ASP.Net comes up with the default solution template with separation of concerns. But at times when we prepare solution architecture we need to have the flexibility built in the DAL, BAL and Presentation layers to take care of dynamic scenarios. What if apart from the ASP.Net MVC one also needs a Web API. What if the Entity Framework needs to be replaced with other object-relational mapper. How easy it would be to modify one layer without touching other layers?
Using the code
First the database was created as database first approach was used. The detail code can be found and further contribution can be made in GitHub
The demo uses a simple table created in SQL Server Express:
StarDesc Table in Database
CREATE TABLE [dbo].[StarDesc] (
[StarName] NVARCHAR (150) NULL,
[StarSize] NVARCHAR (50) NULL,
[StarDistanceFromSun] NVARCHAR (50) NULL,
[StarGalaxyName] NVARCHAR (50) NULL,
[StarBrightness] NVARCHAR (50) NULL,
[SpectralType] NVARCHAR (50) NULL,
[Id] INT IDENTITY (1, 1) NOT NULL,
CONSTRAINT [PK_StarDesc] PRIMARY KEY CLUSTERED ([Id] ASC)
);
SET IDENTITY_INSERT [dbo].[StarDesc] ON
INSERT INTO [dbo].[StarDesc] ([StarName], [StarSize], [StarDistanceFromSun], [StarGalaxyName], [StarBrightness], [SpectralType], [Id]) VALUES (N'10 Lacertae', N'8.27', N'2300', N'Lacerta OB1', N'-4.40', N'O9V', 1)
INSERT INTO [dbo].[StarDesc] ([StarName], [StarSize], [StarDistanceFromSun], [StarGalaxyName], [StarBrightness], [SpectralType], [Id]) VALUES (N'Rigel', N'79', N'863', N'Orion', N'-7.84', N'B8Ia', 2)
INSERT INTO [dbo].[StarDesc] ([StarName], [StarSize], [StarDistanceFromSun], [StarGalaxyName], [StarBrightness], [SpectralType], [Id]) VALUES (N'Sirius ', N'1.71', N'8.6', N'Canis Major', N'1.42', N'A1V', 3)
INSERT INTO [dbo].[StarDesc] ([StarName], [StarSize], [StarDistanceFromSun], [StarGalaxyName], [StarBrightness], [SpectralType], [Id]) VALUES (N'Canopus', N'71', N'320', N'Carina', N'-5.71', N'A9II', 4)
INSERT INTO [dbo].[StarDesc] ([StarName], [StarSize], [StarDistanceFromSun], [StarGalaxyName], [StarBrightness], [SpectralType], [Id]) VALUES (N'Sun', N'1', N'0', N'Milky Way', N'4.83', N'G2V', 5)
INSERT INTO [dbo].[StarDesc] ([StarName], [StarSize], [StarDistanceFromSun], [StarGalaxyName], [StarBrightness], [SpectralType], [Id]) VALUES (N'Arcturus', N'25.4', N'36.66', N'Bootes', N'-0.32', N'K0III', 6)
INSERT INTO [dbo].[StarDesc] ([StarName], [StarSize], [StarDistanceFromSun], [StarGalaxyName], [StarBrightness], [SpectralType], [Id]) VALUES (N'Betelgeuse', N'1180', N'642.5', N'Orion', N'-5.85', N'M1Ia', 7)
SET IDENTITY_INSERT [dbo].[StarDesc] OFF