什么类型的ASP.NET(C#)架构? [英] What type of ASP.NET (C#) architecture?

查看:102
本文介绍了什么类型的ASP.NET(C#)架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Code Project,



最近,我检查了C#.Net中的N-Tier架构。我想问一下(新手问题),当我将dbLayer类放入我的应用程序/ web时,所使用的架构是什么?



dbLayer.cs中的示例代码



 使用系统; 
使用 System.Collections;
使用 System.Collections.Generic;
使用 System.Data;
使用 System.Diagnostics;
使用 System.Data.Sql;
使用 System.Data.SqlClient;
使用 System.Text;
使用 System.IO;
使用 System.Web;
使用 System.Net;

/// < 摘要 >
/// dbLayer的摘要说明
/// < / summary >
public class dbLayer
{
private string gConnString;
public dbLayer( string strConnn)
{
gConnString = strConnn ;
}

public void WebConfig_ActivityLog( string username, string activity)
{
SqlConnection sqlConn = new SqlConnection();
SqlCommand sqlCmd = new SqlCommand();

sqlConn.ConnectionString = gConnString;

sqlCmd.CommandText = dbo。[sp_Activity_Trail];
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Connection = sqlConn;

sqlCmd.Parameters.Add( new System.Data.SqlClient.SqlParameter( @ username,SqlDbType.VarChar, 255 ));
sqlCmd.Parameters.Add( new System.Data.SqlClient.SqlParameter( @ activity,SqlDbType.VarChar, 4000 ));

sqlCmd.Parameters [ @ username]。Value = username;
sqlCmd.Parameters [ @ activity]。Value = activity;

尝试
{
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
}
catch (例外objExp)
{
throw objExp;
}
最后
{
if (sqlConn != null && sqlConn.State!= System.Data.ConnectionState.Closed)
{
sqlConn.Close();
}
}
}
}





谢谢!



我尝试了什么:



从不同架构确认和检查谷歌。

解决方案

取决于你把这个课程放在哪里。它做了什么。它不是DAL,因为它被称为dbLayer(MS建议使用PascalCase类名,所以DBLayer或DbLayer而不是dbLayer)



您应该有类似这样的项目布局(每个都是单独的项目,dll)除了UI,它是初始项目/部署解决方案的一部分:

UI(HTML页面及其后面的代码)

BusinessLogic(域对象和控制器)

数据访问层(从BL调用数据访问)

常见(项目共享的东西,各种扩展,枚举,常量,接口)等)

Hello Code Project,

Recently, I checked the N-Tier Architecture in C#.Net. I would like to ask (newbie question) if what architecture used is when I put dbLayer class in my application/web?

Example code in dbLayer.cs

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
 
/// <summary>
/// Summary description for dbLayer
/// </summary>
public class dbLayer
{
    private string gConnString;
    public dbLayer(string strConnn)
    {
        gConnString = strConnn;
    }
 
    public void WebConfig_ActivityLog(string username, string activity)
    {
        SqlConnection sqlConn = new SqlConnection();
        SqlCommand sqlCmd = new SqlCommand();
 
        sqlConn.ConnectionString = gConnString;
 
        sqlCmd.CommandText = "dbo.[sp_Activity_Trail]";
        sqlCmd.CommandType = CommandType.StoredProcedure;
        sqlCmd.Connection = sqlConn;
 
        sqlCmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@username", SqlDbType.VarChar, 255));
        sqlCmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@activity", SqlDbType.VarChar, 4000));
 
        sqlCmd.Parameters["@username"].Value = username;
        sqlCmd.Parameters["@activity"].Value = activity;
 
        try
        {
            sqlConn.Open();
            sqlCmd.ExecuteNonQuery();
        }
        catch (Exception objExp)
        {
            throw objExp;
        }
        finally
        {
            if (sqlConn != null && sqlConn.State != System.Data.ConnectionState.Closed)
            {
                sqlConn.Close();
            }
        }
    }
}



Thank you!

What I have tried:

Confirmation and checking google from different architecture.

解决方案

Depends on where you put this class. And what it does. It is not DAL just because it is called dbLayer (MS recommends having PascalCase class names, so DBLayer or DbLayer instead of dbLayer)

You should have project layout something like this (each of these is separate project, dll) except for UI which is part of the initial project/solution for deployment:
UI (HTML Pages and their code behind)
BusinessLogic (domain objects and controllers)
Data Access Layer (called from BL for data access)
Common (things shared across the projects, various extensions, enums, constants, interfaces etc.)


这篇关于什么类型的ASP.NET(C#)架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆