잊지 않겠습니다.

1. IIS
* IIS의 pipe line mode
> ISAPI mode : class mode라고도 불리우며, 이는 file의 확장자를 기준으로 ISAPI 확장에 의하여 처리된다.
> Integrated mode : .NET이 pipe line의 일부이기 때문에 특정 file의 확장자와 관련된 어떠한 ISAPI mode가 필요하지 않는다.

System.Web.Routing.UrlRoutingModule 에 의하여 Url의 Routing이 처리가 된다.
이는 Url의 모든 파일이나 내용이 .NET에 의하여 관리되는 것을 의미한다.

2. Routing
System.Web.Routing.UrlRoutingModule은 요청을 받는 즉시 System.Web.Routing을 실행한다.
Routing의 역활은 먼저, Disk의 파일과의 연관성을 찾아내고 파일과의 연관성이 없는 경우, URL 패턴을 인식하고 분석하여 내부 Component가 사용할 수 있는 Request context 데이터 구조를 구성한다. 파일과의 연관성이 발견되는 경우, 파일에 대하여 실행이 되게 된다. 정적 resource 파일들(*.jpg와 같은 그림 파일이나 html 파일들)에 대하여 제공 및 aspx 파일에 대한 WebForm 실행이 이루어진다.
Routing 구성은 System.Web.Routing.RouteTable이라는 static collection안에 놓여진다. 그 Collection안의 entry는 서로 다른 URL pattern을 표현하는데 이 부분의 경우에는 Global.asax 파일안에 RegisterRoutes() method로 사용자가 구성이 가능하다.

3. Controller & Action
기본적으로 MvcRouteHandler라는 Routing 처리기를 이용해서 구성이 되며, Routing 결과에 따라 ControllerFactory에서 Controller를 생성하게 된다. 이 과정에서 MvcRouterHandler는 MVC Controller를 찾아내고, Action method의 매개변수를 제공한다. 이 과정은 Assembly reflection을 이용하고 있으며 모든 IController interface를 가지고 이름이 *Controller로 끝이 나는 모든 public class를 ControllerFactory에 등록하고, 들어온 URL 결과에 따라 특정 Controller를 실행하고, 그에 맞는 Action method를 실행한다. 따라서, Controller에서 직접 Response를 제어할 수 있으나, MVC에서는 이를 권장하지 않는다. MVC에서는 계획된 출력을 의미하는 ActionResult 객체를 반환하는 것이 권장된다.

4. ActionResult & View
Controller에서 제공된 ActionResult를 이용하여 View를 Render하는 과정이다. 기본적으로 View의 Render는 IViewEngine을 구현하는 .NET class를 통해서 구현되는데 기본적으로 WebFormViewEngine을 사용한다. 이름을 보면 알 수 있듯이 이는 기존의 WebForm이 Render 될 때 사용되는 View Engine과 동일하다. 그러나 MVC의 '관계의 분리' 개념에 따라 View는 HTML을 생성하는 것 이외에는 어떠한 일을 하지 않는다.
 

Posted by Y2K
,
.NET MVC 및 모든 Component Model에서 Entry의 에러를 표시하는데 사용되는 Interface.
인터페이스는 각 Property에 대한 값을 검사할 수 있도록 this[columnName]에 대한 정의와 객체의 에러 상태를 알아볼 수 있는 Error 라는 string property를 지원한다.

여기에서 각 에러값은 null이 반환될 때, 에러가 없다고 가정이 되며, String.Empty가 반환되는 경우에도 에러라고 인식하게 된다.(ASP.NET MVC)

사용예는 다음과 같다.

[Table(Name="Product")]
public class Product : IDataErrorInfo 
{
    [Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
    public int ProductId { get; set; }
    [Column]
    public string Name { get; set; }
    [Column]
    public string Description { get; set; }
    [Column]
    public decimal Price { get; set; }
    [Column]
    public string Category { get; set; }

    #region IDataErrorInfo Members

    public string Error
    {
        get { return null; }
    }

    public string this[string columnName]
    {
        get
        {
            if((columnName == "Name") && string.IsNullOrEmpty(Name))
                return "Please enter a product name";
            if((columnName == "Description") && string.IsNullOrEmpty(Description))
                return "Please enter a description";
            if((columnName == "Price") && (Price <= 0))
                return "Price must not be negative or zero";
            if((columnName == "Category") && string.IsNullOrEmpty(Category))
                return "Please specify a category";
            return null;
        }
    }

    #endregion
}
Posted by Y2K
,
복불복이나 사다리타기 같은 프로그램을 간단히 만들어보자라는 생각으로 잡았다가 은근히 일이 커져버렸다.;
Random으로 어떻게하면 뽑아낼 수 있을지, 요즘 고민되고 있는 Domain-Driven 방법을 어떻게하면 적용할 수 있을지를 고민하다가,
별것도 아닌것에 시간을 다 잡아먹어버린것 같다.;

ASP .NET MVC에서 AJAX도 사용해보고, Castle container도 사용해보고.. 이것저것 사용해보면서 재미를 느낀 짬짬이 취미생활.;

Domain Model 구성은 다음과 같다. 데이터를 따로 제공하지 않아도 되어서 Repository는 비어있는 상태


핵심이된 List Shuffle method.
    static class ShuffledList
    {
        public static List Shuffle(this List list)
        {
            string[] shuffledList = new string[list.Count];
            List freeIndex = new List();
            Random rand = new Random();

            for(int i = 0 ; i < list.Count ; i++)
            {
                freeIndex.Add(i);
            }

            foreach(string item in list)
            {
                int indexOfNewIdx = rand.Next(freeIndex.Count);
                int newIdxOfCard = freeIndex[indexOfNewIdx];

                shuffledList[newIdxOfCard] = item;
                freeIndex.Remove(newIdxOfCard);
            }
            return shuffledList.ToList();
        }
    }



Domain-Driven으로 3tier로 작성해주면서.. 참 이렇게 편하고 좋은 방법을 내가 돌아가고 있었구나.. 하는 후회가 엄청나게 된다.
많은 것을 더 배워야지 되는데. 나태해진 내 자신도 반성이 되고 말이야.;
Posted by Y2K
,