C# - Proper Implementation Of N-layer Architecture?
Feb 28, 2011
I have been learning C# for the last year or so and trying to incorporate best practices along the way. Between StackOverflow and other web resources, I thought I was on the right track to properly separating my concerns, but now I am having some doubts and want to make sure I am going down the right path before I convert my entire website over to this new architecture.
The current website is old ASP VBscript and has a existing database that is pretty ugly (no foreign keys and such) so at least for the first version in .NET I do not want to use and have to learn any ORM tools at this time.
I have the following items that are in separate namespaces and setup so that the UI layer can only see the DTOs and Business layers, and the Data layer can only be seen from the Business layer. Here is a simple example:
[Code]....
Am I completely off base? Should I also have the same properties in my BLL and not pass back DTOs to my UI? what is wrong and what is right. Keep in mind I am not a expert yet.
I would like to implement interfaces to my architecture, but I am still learning how to do that.
I'm fairly new to dependency injection but it seems like a proper DI implementation will be fairly complex.
For example, DI requires a centralized class that manages the configuration and resolves the dependencies at runtime.
DI is also based on the concept of using interfaces. For example, a SpecialLogger should use an ILogger interface.
The centralized DI manager class will need to register types - for example, associate ILogger to SpecialLogger.
SpecialLogger will also need to implement the ILogger interface so SpecialLogger can be used through the DI ILogger interface.
Therefore, it seems like a sln using DI will need multiple projects to support DI. Here is an example for logging:
* MyCompany.MyDivision.Framework.DI.Management - this would have the DI manager where dependency types are registered and resolved at runtime * MyCompany.MyDivision.Framework.Logging - this would have the implementation of a logging class. The main logging class would need to implement ILogger. * MyCompany.MyDivision.Framework.DI.Interfaces - this would have the ILogger interface.
Interfaces would need to be stored in a separate class library from the DI manager because both the DI manager and SpecialLogger use the ILogger interface. Since the DI manager associates SpecialLogger to ILogger a circular reference would be encountered without a separate class library to store the ILogger interface.
I'm currently implementing a project using asp.net, c# and the MVP (Model-View-Presenter) pattern. The main purpose of this solution is to deliver a graph to the consumer, to be used by a variety of systems. It is basically a custom graph server.
The view page in this particular case has an MSChart control on it, which has to be dynamically populated and configured based on parameters in the QueryString. This can be as diverse as totally different types of data sets, display modes and so on, using a lot of the properties of the chart control.
Many of these properties are again of types which are particular to the chart control and would require the same dependencies as the chart control itself if they are to be set by the presenter.
I'm trying to figure out the best way to expose the properties to the presenter so it can work its magic.
Should I:
Just expose the whole chart object and live with a system.web type dependency in the presenter project? Make accessor and translation properties for all of the chart control properties so that I don't have the dependency, but add lots of complexity? Other, that I haven't thought of?
To me it seems that it would be against the MVP pattern to bubble a display control up into the presenter, but it seems that trying to map all the properties to DTOs or similar would be a lot of work that would add a lot of complexity, and while the solution would be somewhat more loosely coupled, I'm not sure the gain would be worth it in this case. How would you implement something like this, given MVP?
I am new to this .NET what is the difference between N-Tier and 3- Tier Architecture. If they are same. How to pass the values from presentation layer to business logic layer.
For Example
I have 10 controls in presentation layer. I passing values to these controls. How the architecture works.
I am building a web site following the tutorials on asp.net. I am using dataset as data access lay, and writing classes to access the dataset. But the example is just basic ideas, how do I retrieve individual table column value in the business layer?For example, if I have a table called Product, I only want to find out what is the product name by product id. I did this in my ProductBLL:
public ProductBLL { public int GetProductName(string productId) { ProductDataSet.ProductDataTable prodData = Adapter.GetProductById(productId); [code]...
Is there a better way, or am I doing this correctly? Can anybody give me a reference to a more complicated business logic model?
I have implemented the 3-tier architecture project; DAL, BAL, and presentation layer are three layers in it. I am going to implement the following scenario:
Presentation layer calls to a function in the BAL layer which returns 2 string variable, and in turn this function from BAL layer calls to a DAL layer function which also returns 2 string variable. How can I implement the above scenario?
here i have in 3-tier architecture , how to pass the data between DAL and BAL. i am using grid view to edit the data,when ever i click on the edit button all the corresponding fields should come to textboxes. i tried for delete ,it works fine bt not working to EDIT.
I need to know the best way to do the following. I have nested business level APIs (say level 1 & level 2). L1 needs to call L2. Both APIs use the database layer directly at their own nesting levels.
Now, in the database layer, I fetch the db connection from the pool each time as follows:
SqlConnection conn = new SqlConnection(connString); conn.Open();
Is it proper to fetch the db connection each time on every DB level call as above? I know it will return a connection from the ASP.NET connection pool. However, wouldn't it be better to maintain the same DB connection throughout the nested calls (or throughout the current http request lifetime)? Will fetching a connection from the pool each time cause issues with nested TransactionScopes?
I'm developing a n-tier architecture... I'm confused with handling exception in the layers... Is it a good practise to add a Exception Layer to the architecture.
I'm conducting a project in which a website should have multi-language support.Now, this website is supposed to serve about 500K+ visitors a day, so it must be super-efficient.
I've created a table of parameters {[ID],[Name]} AND a linkage-table {[objectID],[parameterID],[languageID],[value]}. I think it's the best way to deploy multi-language support while having the privilege to translate different parameters for each language.
As far as I know, server's memory is much faster than a physical HDD. Therefore, I'm planning to store ASP.NET Application State objects for my translation architecture.[URL]
I am working on a web application project with a layered architectural style having DAL, BLL, Service Layer and Presentation Layer. It's going to be a Web forms application.
My intent is to try using some of the new features of .Net 3.5 or 4.0.
Currently, I am thinking through different approaches for implementing Authentication in this project.
I have a query regarding the design of the application, particularly Authentication.
In which layer should I have Authentication class? BLL? If I implement the Authentication class in BLL, should I be having an app.config in the same class library project to contain the Database connection string and all.
In a project im working on there are many sql tables containing different ID, Name pairs. Those are represented as Enums in classes that need them however that requires casting since tables contain ID only.Also when serialize the Enum contains the ID not value.
not sure if I'm posting to the right thread or not.. but here is the questiondoes anyone know how to implement a best pratice on SEO?One of the example is: if the user types "brand new canon camera" then I want the system to find a sequence of string in the database that contains "new", "cannon", "camera". It is ok with or without the word "brand". However if the user types "HP laptop DV1000" and i want the system to find all HP laptop whether new or not but limited to specific series.
I am in the process of redesigning our main product, a knowledge database system for clients to access clinical and specialist advice articles. There is a requirement to add "Social Networking" to this allowing users to connect and post remarks etc...
This is somewhat similar to the Facebook wall scenario - where Articles, Photos, Groups, Products, Events, ActivityFeed can all have comments. I am at a lose as to the database design I would need to implement this. All comments must allow for Moderation/Approval/Spam Reporting etc...
I originally thought a individual table for each Comments entity ex: ArticleComment, ProductComment would work as the comments themselves are not all directly related. Each table having the same exact columns. But this makes life abit awkward as then this creates a separation between something that for all purposes is the same i.e. They are all comments.
The other design idea was to have a single Comment table with an "arc" type relationship to related tables with FK references back to the source.
The other option was to have a single Comment table with an Object Type and XID but this breaks the rules of relation and does not all for referential integrity.
I am at a lose and don't know what to do. I have asked over at SQLCentral.com and all I have done is raised more questions than answers about what to do.
Design 1: This would require exact copies of this table for all the entities.
-- Photo Comments -- CREATE TABLE dbo.PhotoComment ( CommentID int IDENTITY(1,1) NOT NULL, PhotoID int NOT NULL, Body ntext NOT NULL, ReportedAsSpam bit NOT NULL CONSTRAINT [DF_PhotoComment_ReportedAsSpam] DEFAULT (0), IsSpam bit NOT NULL CONSTRAINT [DF_PhotoComment_IsSpam] DEFAULT (0), IsApproved bit NOT NULL CONSTRAINT [DF_PhotoComment_IsApproved] DEFAULT (1), CreatedDate datetime NOT NULL, CreatedBy uniqueidentifier NOT NULL, UpdatedDate datetime NOT NULL, UpdatedBy uniqueidentifier NOT NULL, IsDeleted bit NOT NULL CONSTRAINT [DF_PhotoComment_IsDeleted] DEFAULT (0), CONSTRAINT [PK_PhotoComment] PRIMARY KEY (CommentID), CONSTRAINT [FK_PhotoComment_PhotoID] FOREIGN KEY (PhotoID) REFERENCES dbo.Photo(PhotoID), CONSTRAINT [FK_PhotoComment_CreatedBy] FOREIGN KEY (CreatedBy) REFERENCES dbo.aspnet_Users(UserId), CONSTRAINT [FK_PhotoComment_UpdatedBy] FOREIGN KEY (UpdatedBy) REFERENCES dbo.aspnet_Users(UserId) )
Design 2: The "Arc" relationship
CREATE TABLE dbo.Comment ( CommentID int IDENTITY(1,1) NOT NULL, CommentType char(1) NOT NULL CHECK(CommentType IN ('A','I','E','G','U','P')), Body ntext NOT NULL, ReportedAsSpam bit NOT NULL CONSTRAINT [DF_Comment_ReportedAsSpam] DEFAULT (0), IsSpam bit NOT NULL CONSTRAINT [DF_Comment_IsSpam] DEFAULT (0), IsApproved bit NOT NULL CONSTRAINT [DF_Comment_IsApproved] DEFAULT (1), CreatedDate datetime NOT NULL, CreatedBy uniqueidentifier NOT NULL, UpdatedDate datetime NOT NULL, UpdatedBy uniqueidentifier NOT NULL, IsDeleted bit NOT NULL CONSTRAINT [DF_Comment_IsDeleted] DEFAULT (0), CONSTRAINT [PK_Comment] PRIMARY KEY (CommentID), CONSTRAINT [FK_Comment_CreatedBy] FOREIGN KEY (CreatedBy) REFERENCES dbo.aspnet_Users(UserId), CONSTRAINT [FK_Comment_UpdatedBy] FOREIGN KEY (UpdatedBy) REFERENCES dbo.aspnet_Users(UserId), CONSTRAINT [UC_Comment_CommentID_CommentType] UNIQUE (CommentID, CommentType) )
CREATE TABLE dbo.Comment ( CommentID int IDENTITY(1,1) NOT NULL, ObjectType char(1) NOT NULL, /* A = Article, P = Photo etc... */ XID int NOT NULL, /* Would be the ID of the main entity being queried. */ Body ntext NOT NULL, ReportedAsSpam bit NOT NULL CONSTRAINT [DF_Comment_ReportedAsSpam] DEFAULT (0), IsSpam bit NOT NULL CONSTRAINT [DF_Comment_IsSpam] DEFAULT (0), IsApproved bit NOT NULL CONSTRAINT [DF_Comment_IsApproved] DEFAULT (1), CreatedDate datetime NOT NULL, CreatedBy uniqueidentifier NOT NULL, UpdatedDate datetime NOT NULL, UpdatedBy uniqueidentifier NOT NULL, IsDeleted bit NOT NULL CONSTRAINT [DF_Comment_IsDeleted] DEFAULT (0), CONSTRAINT [PK_Comment] PRIMARY KEY (CommentID), CONSTRAINT [FK_Comment_CreatedBy] FOREIGN KEY (CreatedBy) REFERENCES dbo.aspnet_Users(UserId), CONSTRAINT [FK_Comment_UpdatedBy] FOREIGN KEY (UpdatedBy) REFERENCES dbo.aspnet_Users(UserId), CONSTRAINT [UC_Comment_CommentID_ObjectType_XID] UNIQUE (CommentID, ObjectType, XID) ) -- Ex: Get all comments for article ID 23. SELECT * FROM Comment Where ObjectType ='A' and XID = '23'
I am implementing 3-tier architecture. I just wanted to know the role of business layer in 3-tier architecture.
I am developing application in using entity framework. So I have entity object which is accessiable in PL,BL & DL. My question is whether input assignment to entity object should be in PL OR BL.(Consider there is save method)
i build online course selection for a university now i want to make it layering and i dont know to make it 2 layer or 3 layer i mean mix business layer and database layer because i use linq so it is not require to check request data that in sql from client in business layer because linq check it autimatically to preent injection and etc.is it right?can i put my class and DB class in same place or layer?if i make it 2 layer the performance becom better?
whats is the difference three tier and three layer architecture. I need three tier architecture which is fulfill the object oriented requirement. and database change flexibility.
I am creating an ASP.NET MVC application and want to display an icon in the view based on a value of a property in the model. I guess I want to have the logic deciding which image to show in the business layer (which is in a separate class library project) but the actual images files in the web application's "Content" folder. Should I set the url of the image in the business layer? I don't want the business layer to know that is serves a web application, it can be a Windows Form or WPF application as well. If I set the url with System.Web.HttpContext.Current.Server.MapPath it feels like I am getting an unwanted dependency on System.Web, right? What are the options here?
I am making use of 3-tier architecture.In UI layer, i am getting user input and converting it into XML document. But now question arises that how can i pass this xml document to business and data access layer?
I am working on implementing a web application in ASP.Net by following the MVC design pattern (Not ASP.Net MVC). As part of the design, we have entity objects that has only properties as per the corresponding table structure and the idea is using these entity objects in the view layer and the same entity objects are passed to Persistence Layer for saving the data to the database. Business Objects in the business layer are responsible for interacting with the database.
As view creates the entity objects and passes to next layer, what would be the best practice to pass the entity objects to the business layer? Should the business objects accept data objects as parameters and interact with the persistence layer? Is there any other best practice to pass the required objects from the view layer to the next layer? As business objects also need to access the properties of the entity objects passed from the view layer, do we need any "translation" from entity objects to business objects?
the best practices to pass entity objects from view layer to the next layer and also how the entity objects created by the persistence layer can be used by business objects?
So my asp.net is very very rusty, and i'm trying to get back into best practices and what not. So, I whip out google and start looking for examples and samples and tutorials, but what do I find? Old crusty stuff that tends to be written even before "the latest" technology was released back in the stone age.Sure, the concepts may still hold up. But the actual implementations are basically useless. I'm looking for something using Linq, n-layers (not tiers. Tiers can be a layer, but a layer is not necessarily a tier) some kind of current ORM (L2S, EF, etc..) and some real-world stuff, not abitrary and useless examples.
I am using stored procedure in my Web application. I am creating SQL Command binding this command with Stored procedure name and parameters and executing.
The problem is for each Stored procedure i need to create separate function for each stored procedure defined.
Is there any way that I can define a single function for n number of stored procedure.