patterncsharpMinor
Simple CRUD application with n layered architecture
Viewed 0 times
simplearchitectureapplicationlayeredwithcrud
Problem
I had a technical test with a simple CRUD application where I used n layered architecture as explained on the Patterns In Action book that I bought.
However after delivering one of their feedbacks was the following.
DbContext lifetime is completely wrong. (literally)
I will copy the relevant files on this question, because I want to learn what I did wrong and if that product I bought has just problems conceptually.
So, in my
Then I have also this Interface
And now, in the EntityFramework namespace I have the following implementations
```
namespace DataObjects.EntityFramework
{
// Data access object factory
// ** Factory Pattern
However after delivering one of their feedbacks was the following.
DbContext lifetime is completely wrong. (literally)
I will copy the relevant files on this question, because I want to learn what I did wrong and if that product I bought has just problems conceptually.
So, in my
DataAccess class library I have this:namespace DataObjects
{
// abstract factory interface. Creates data access objects.
// ** GoF Design Pattern: Factory.
public interface IDaoFactory
{
//Product Dao interface that must be implemented by each provider
IProductDao ProductDao { get; }
//Color Dao interface that must be implemented by each provider
IColorDao ColorDao { get; }
//Size Dao interface that must be implemented by each provider
ISizeDao SizeDao { get; }
//Category Dao interface that must be implemented by each provider
ICategoryDao CategoryDao { get; }
//File Dao interface that must be implemented by each provider
IFileDao FileDao { get; }
//File Error Dao that must be implemented by each interface
IFileErrorDao FileErrorDao { get; }
}
}Then I have also this Interface
using BusinessObjects;
using System.Collections.Generic;
namespace DataObjects
{
public interface ICategoryDao
{
//Gets a list of categories
List GetCategories();
//Inserts one category
void InsertCategory(Category category);
//To verify if category exists
bool CategoryExists(string category);
//Get Category by name
Category GetCategoryByName(string category);
}
}And now, in the EntityFramework namespace I have the following implementations
```
namespace DataObjects.EntityFramework
{
// Data access object factory
// ** Factory Pattern
Solution
I don't see any reason for why the lifetime of the
The only things that I'm not so fond of are
DbContext should be completely wrong. It's too general and probably just meant to not let you pass the question.The only things that I'm not so fond of are
- the mapping between the EF entities and and DTOs - why would you want to do this? Don't you have more interesting code to write? ;-)
- the
Daosuffix polution everywhere.
- I've never seen any real world application where something as trivial as CRUD only would work. You always have joins and other sophisticated inserts so it's nice only in theory. You also almost never need CRUD interfaces for every entity type becasue some of them cannot exist without some other ones and need to be inserted/deleted together.
Context
StackExchange Code Review Q#162934, answer score: 2
Revisions (0)
No revisions yet.