Asynchronous Programming in .NET

written by Bipin Joshi
translated by Asptomorrow
소 개

  .NET 프레임워크 에서 비동기 프로그래밍의 지원은 잘 구현되어 있다. 비동기 프로그래밍 모델은 전체 성능을 향상시킬 뿐만아니라 응용프로그램들을 더욱더 응답적이게(responsive) 해준다. 이 강좌에서 비동기 프로그램을 이용하는 컴퍼넌트를 개발하는 완성된 예제를 보여 줄 것이다.

예제에 대해서

  우리는 비동기 프로그래밍에 대한 지원을 하는 컴퍼넌트를 작성하는 방법을 보여주는 예제를 만들 것이다. 또한 여러분은 컴퍼넌트를 동기적으로 호출하는 방법을 일반적으로 사용하고 있다는 것을 명심하고, 우리는 직원의 월급을 계산하도록 해주는 간단한 프로그램을 개발할 것이다. 먼저 동기적으로 작동하는 프로그램을 만들어서 잘 작동되는지 알아보고, 조금씩 비동기 프로그래밍 기능을 하도록 추가할 것이다.

컴퍼넌트 생성하기

  여러분이 만일 VS.NET 을 사용한다면, C#으로 프로젝트의 새로운 컴퍼넌트 라이브러리 타입을 만들면서 시작할 수 있다. VS.NET을 사용하지 않는다면, Text 에디터에서 .cs 파일을 만들고, 라이브러리(DLL)로 컴파일할 수 있다. 다음 코드는 SalaryCalc 컴퍼넌트를 보여준다.

namespace AsyncProgDemo{public class SalaryCalc{	public SalaryCalc()	{	}	public string Calculate()	{	Console.WriteLine("Inside Calculate()...");	Console.WriteLine("Caclulating salaries...");	Console.WriteLine("Done...");	return "ok";	}}}


  여러분이 위에서 보는 소스는 실제 로직이 들어있지 않은 매우 간단한 코드이다. Salarycalc 라는 클래스를 포함하는 AsyncProgDemo라는 네임스페이스를 만든다. 이 클래스는 한 집단의 모든 직원의 월급을 계산하는 Calculate라는 한개의 메서드를 가지고 있다. 다 마쳐지면 메서드는 "OK" 라는 문자열을 리턴한다.

SalaryCalc 컴퍼넌트를 사용하는 클라이언트 프로그램 만들기

  이 컴퍼넌트를 사용하는 콘솔 프로그램을 만들어보자.

using System;namespace AsyncProgDemo{	class Client	{		static void Main(string[] args)		{			SalaryCalc sc=new SalaryCalc();			sc.Calculate();		}	}}


  이 프로그램은 매우 직관적이어서 설명이 필요없을 것이다.

비동기프로그램 컴퍼넌트에 대한 코딩 가이드라인

  실제 코딩에 들어가기 전에, 비동기 컴퍼넌트 설계시 추천할만한 가이드라인이 무엇이 있는지 알아보자.

    ■ 비동기 뿐만 아니라 동기적으로도 메서드를 호출할수 있는 기능 제공

    ■ 필요에 따라 클라이언트(caller 응용프로그램)이 호출되는 메서드의 버전을 결정할수 있도록 하는 기능

    ■ 동기적으로 호출한 메서드를 만들기 위해 클라이언트 응용프로그램을 수정하지 않는다. 클라이언트 는 컴퍼넌트에의해 어떻게 호출되는지 모르도록 진행되어야 한다.

비동기프로그램 메서드에 대한 코딩 가이드라인

  여러분의 비동기 컴퍼넌트는 메서드를 위해서 다음과 같은 가이드라인을 준수해야한다.

    ■ 다음과 같은 시그너쳐를 매칭시키는 컴퍼넌트를 작성한다.

        □ public XXXX()

        □ public IAsyncResult BeginXXXX(AsyncCallback ac, Object state)

        □ public EndXXXX(IAsyncResult result)

  위의 메서드 중에서 XXXX는 메서드 이름을 나타낸다. 예를들어, 앞에서 본 소스의 경우 Calculate, BeginCalculate, EndCalculate 메서드로 쓸 수 있다. EndXXXX 의 리턴 타입은 여러분의 메서드에서 원했던 리턴타입과 같다. (이 경우 string 일것이다)

  BeginXXXX 메서드의 경우 다음과 같은 사항을 기억하자.

    ■ 모든 IN 파라미터를 포함한다.

    ■ 모든 OUT 파라니터를 포함한다.

    ■ 모든 IN/OUT 파라미터를 포함한다.

    ■ 마지막 두개의 파라미터로 AsyncCallback과 object를 받아들인다.

    ■ ISyncResult를 리턴한다.

  EndXXXX 메서드의 경우 다음과 같은 사항을 기억하자.

    ■ 모든 IN/OUT 파라미터를 포함한다.

    ■ 모든 OUT 파라니터를 포함한다.

    ■ IAsyncResult를 마지막 파라미터로 받아들인다.

    ■ 여러분이 원하는 데이터 타입으로 값들을 반환한다.

  우리가 만든 메서드는 다른 파라미터를 포함하지 않았지만 여러분은 다른 메서드들과 마찬가지 방법을 사용할 수 있다.

네임스페이스 포함시키기

  위의 예제가 잘 작동하려면 여러분은 다음과 같은 네임스페이스를 컴퍼넌트에 추가시켜야 한다.

  ■ System

  ■ System.Runtime.Remoting.Messaging

SalaryCalc 변형하기

using System;using System.Runtime.Remoting.Messaging;namespace AsyncProgDemo{public class SalaryCalc{public delegate string CalcDelegate();public SalaryCalc(){}public string Calculate(){	Console.WriteLine("Inside Calculate()...");	Console.WriteLine("Caclulating salaries...");	Console.WriteLine("Done...");	return "ok";}public IAsyncResult BeginCalculate(AsyncCallback ac,Object state){	CalcDelegate cd=	new CalcDelegate(this.Calculate);			IAsyncResult result=	cd.BeginInvoke(ac,state);	return result;}public string EndCalculate(IAsyncResult result){	CalcDelegate cd=(CalcDelegate)	((AsyncResult)result).AsyncDelegate;		object o=cd.EndInvoke(result);	return (string)o;}}}


  여기서, 원래 클래스에서 몇가지 부분을 추가시켰다.

  ■ 위에서 언급한 시그너쳐를 매칭시키는 BeginCalculate 메서드를 추가한다.

  ■ 위에서 언급한 시그너쳐를 매칭시키는 EndCalculate 메서드를 추가한다.

  ■ BeginCalculate 메서드 내부에서 delegate를 끝냈다. 이 메서드는 컴퍼넌트에서부터 callback 을 받은 후에 클라이언트에 의해 호출될 것이다. callback은 Calculate() 메서드가 종료될때 자동으로 호출된다.

클라이언트의 변형된 버전

  이 컴퍼넌트의 비동기적인 특징을 사용하기 위해 우리는 클라이언트를 다음과 같이 바꿀 필요가 있다.

using System;using System.Threading;using System.Runtime.Remoting.Messaging;namespace AsyncProgDemo{class Client{static void Main(string[] args){	SalaryCalc sc=new SalaryCalc();	AsyncCallback ac=new AsyncCallback(MyCallback);	IAsyncResult result=sc.BeginCalculate(ac,sc);	Thread.Sleep(5000);}public static void MyCallback(IAsyncResult result){SalaryCalc sc=(SalaryCalc)result.AsyncState;object o=sc.EndCalculate(result);Console.WriteLine("Inside Callback...");Console.WriteLine("Result of salary Calculation:" + o);}}}


  여기서 Calculate() 메서드를 직접 호출하는 대신에, 우리는 callback 메서드를 호출하는(MyVallback) BeginInvoke 메서드를 호출했고, 결과를 얻었다. 우리는 Calculate 메서드를 직접 호출했을때 같은 결과가 나왔다는 것을 알아두자.

결 론

  .NET은 밑바닥에서부터 비동기 프로그래밍을 지원한다. 여러분은 쉽게 함수를 비동기적으로 기능하게 하는 컴퍼넌트를 개발하게 해준다. 앞에서 우리는 그런 컴퍼넌트를 만드는 방법에 대한 예제를 보았고, 또한 그런 컴퍼넌트 개발을 위한 가이드 라인을 알아보았다.

'programming > c#' 카테고리의 다른 글

.NET Enterprise Services 성능  (0) 2004.12.23
VS .Net에서 Macro를 이용하여 #Region 쉽게 추가하기  (0) 2004.12.14
[펌] COM+ 관련 게시물  (0) 2004.11.12

아래 매크로가 #Region을 쉽게 넣어주는 매크로입니다.

매크로 등록은

VS 실행 후 프로젝트를 하나 여신 후 Tools - Macros - Macro IDE 를 실행한 후

MyMacro 폴더 안에 하나 만드시고... 아래 소스를 붙이시면 끝입니다.

 

단축키 없이 사용하기 불편하니

Tools - option - 환경 - 키보드 에서

다음 문자열을 포함하는 명령 표시에 매크로 이름을 넣으면 검색이 될껍니다.

선택한 후 바로 가기 키 누르기에 등록되지 않은 단축키를 하나 지정하시면 준비 끝!!

 

그 다음.. 소스에서 Region으로 지정하고 싶은 부분을 블럭 지정하시고

등록한 단축키를 누르면 대화창이 하나 뜹니다. Region 이름 넣는 부분

이름을 넣으시면 자동으로 Region으로 감싸 줍니다.

편하죠??

 

귀찮아서 그림은 뺐습니다. ^^''

 

출처 : http://blogs.msdn.com/powertoys/archive/2004/04/27/120775.aspx


..more


'programming > c#' 카테고리의 다른 글

[펌] Asynchronous Programming in .NET  (0) 2004.12.15
[펌] COM+ 관련 게시물  (0) 2004.11.12
C#으로 만든 COM+ Componet의 배포 프로젝트...  (0) 2004.11.09

http://www.devpia.com/Forum/BoardView.aspx?no=20029&page=10&Tpage=18&forumname=csharp_qa&stype=&ctType=&answer=&KeyR=title&KeyC=

 

 

1. 일단은 클래스 라이브러리 프로젝트를 선택하시구요...

    COM+를 작성할 것들을 코딩하시구요...

 

2. 일단 COM+를 만들려면 System.EnterpriseService를 참조 추가하시구요...

   그리구 네임스페이스를 적어주시구요...

   그런 다음 만드시는 클래스는 반드시 ServicedComponent를 상속 받아야합니다...

 

3. 아래는 COM+의 주요 서비스들인데요...

   이 서비스들을 이용하시려면 적절한 어트리뷰트를 추가하셔야 하구요...

항목설명
자동 트랜잭션 처리선언적 트랜잭션 처리 기능을 적용합니다.
BYOT(Bring Your Own Transaction)트랜잭션 상속 형식을 허용합니다.
COMTI자동화 개체에서 CICS 및 IMS 응용 프로그램을 캡슐화합니다.
CRM트랜잭션이 없는 리소스에 원자성 및 영속성 속성을 적용합니다.
Just-In-Time 활성화메서드가 호출될 때 개체를 활성화하고 호출이 반환될 때 활성화를 취소합니다.
느슨하게 결합된 이벤트개체 기반 이벤트를 관리합니다.
개체 생성클래스의 인스턴스를 생성할 때 영구 문자열 값을 인스턴스에 전달합니다.
개체 풀링이미 만들어진 개체들이 포함된 풀을 제공합니다.
전용 구성 요소out-of-process 호출로부터 구성 요소를 보호합니다.
대기열 사용 구성 요소비동기 메시지 대기열을 제공합니다.
역할 기반 보안 역할에 따라 보안 권한을 적용합니다.
SOAP 서비스구성 요소를 XML Web services로 게시합니다.
동기화동시성을 관리합니다.
XA 상호 운용성X/Open 트랜잭션 처리 모델을 지원합니다.

 

4. 해당 기능들을 다 정의 했다고 한다면...

    강력한 이름의 어셈블리를 추가해야 합니다...

    그럴려면 프로젝트 파일 중에서 AssemblyInfo.cs 파일을 여시구요...

    [assembly: AssemblyKeyFile("")] 이 부분에 KeyFile의 경로를 설정하셔야 합니다...

    키 생성은 sn.exe를 이용하면 됩니다...

    sn -k XXXX.snk

 

5. 이제 모든 것이 완료되었습니다...

   이 프로젝트를 빌드하시면 DLL 파일이 생깁니다...

   이 DLL 파일을 이용해서 이제 COM+에 등록을 해야 합니다...

 

6. 전역 어셈블리에 추가하시려면 gacutil.exe를 이용하셔서 전역 어셈블리에 등록을 하셔야 합니다...

 

ex) gacutil /i c:\mydll.dll

 

7. 이제 COM+ 응용 프로그램에 등록하실 차례인데요...

   regsvcs.exe를 이용하셔서 COM+ 응용 프로그램에 등록하시면 됩니다...

regsvcs /appname:myTargetApp c:\myTest.dll

 

 

8. 이렇게 되면 이제 모든 것이 완료 되었습니다...

    확인하시려면 구성요소 서비스에서 등록한 COM+ 응용 프로그램이 있는지 확인하시면 됩니다...

 

* 참고 자료 : MSDN에서 COM+라고 치시면 많은 관련 문서들이 있습니다...

그럼!~~~

C#으로 Component만들어 돌려보고...

배포 쪽 확인 작업 중...

 

SETUP Project를 통해 GAC에 등록하는 것까지는 했는데... 구성요소서비스에 등록하는 방법(Batch 파일을 통한 방법 말고)을 찾던 중... 매우 쉽게 하는 방법을 찾았다 --;;

 

시작-관리도구-구성요소서비스 에서...

등록된 컴포넌트를 선택하고 오른쪽 마우스 버튼을 누르면 '내보내기'라고 나온다..

 

이것 선택하면 설치 파일이 자동 생성된다 MSI파일과 CAB파일...

 

이것만 가지고 실제 작업 서버에서 실행하면 GAC등록은 물론 구성요소서비스에도 자동 등록된다....

 

쩝... 허무했다 너무 간단해서...

 

혹시 SET Project에서 구성요소서비스에 등록하는 법을 알고 계신분 답글 부탁드립니다.

'programming > c#' 카테고리의 다른 글

[펌] COM+ 관련 게시물  (0) 2004.11.12
[펌] COM + 의 Server 방식과 Library 방식의 차이  (0) 2004.11.09
Registering Assemblies  (0) 2004.11.09

개체가 생성되는 프로세서가 다릅니다.

 

Library 방식은 호출자의 프로세서 내에 생기지만 Server 방식은 다른 프로세스(Dllhost.exe)에서 생성되어 서비스됩니다.

 

Server 방식일 경우

참조하고 있는 개체가 혹시나 죽어버려도 호출자 프로세스에 영향을 안미쳐서 안전성에 좋지만,

다른 프로세스에 있는 개체를 원격 호출하기 때문에 느린 단점이 있습니다.

 

Library 방식일 경우

참조하고 있는 개체가 죽어버리면 속해 있는 프로세스도 같이 죽을 수도 있지만,

같은 프로세스 내에서 생성되기 때문에 속도가 빠릅니다.

 

하지만, .NET 런타임은 안전한 환경(AppDomain을 통한 격리 환경, 예외 처리)을 제공하기 때문에 .NET을 기반으로 하는 MS 제품을 살펴보면 전에 Server 방식으로 제작되었던 부분도 Library방식으로 제작되는 것을 볼 수 있습니다.

GAC에 공유 어셈블리를 등록하는 방법은 크게 세 가지가 있다는건 알았는데...

구체적으로 어떻게 하는지 궁금했었는데.. 여기 세 가지 방법이 나오네요.

쿠쿠..

 

 

To add the serviced components in your assembly to a COM+ application, you need to register that assembly with COM+. You can perform that registration in three ways:

  • Manually, using a command line utility called RegSvcs.exe.

  • Dynamically, by having the client program register your assembly automatically.

  • Programmatically, by writing code that does the registration for you using a utility class provided by .NET.

 


..more


  • commmand line에서 RegSvcs.exe utility를 사용하여서 수동적으로 등록 하는 방법
    • 수동적으로 component를 등록하기 위해서는 command line에서 RegSvcs.exe utility를 사용합니다 ( 이후에는 아마 Visual Studio .NET에서 RegSvcs를 호출할 수 있도록 합니다. 만약 하나의 DLL assembly MyAssembly.dll을 MyApp라는 COM+ application에 assembly를 추가 하고 싶을때는 RegSvcs.exe /appname:MyApp MyAssembly.dll 입니다.
    • 기본적으로 RegSvcs COM+ application에 구성된 것을 override하지 않습니다. 만약 assembly 버전이 이미 등록된 COM+ application이 있다면 RegSvcs는 아무 일도 하지 않을 것입니다. 만약 버전이 아직 등록되어 있지 않다면, 새로운 버전을 추가 하고 새로운 CLSID를 할당 할 것입니다.
  • client program에서 COM+ application을 사용하여서 자동적으로 등록 하는 방법
  • .NET에서 제공하는 등록 utility 클래스를 사용하여 프로그램에서 등록하는 방법

..more


DNS서버로부터 조회를 해서 MX(Mail Exchange) record를 얻어와야 하는데...

첨부 파일은 출처에 있는 파일이고...

 

아래 소스는 실제 사용예 입니다.

 

  DnsLib.DnsLite dns = new DnsLite();
  ArrayList dnsServer = new ArrayList();
  dnsServer.Add("164.124.101.2");               // 데이콤 DNS 서버 주소입니다.

  dns.setDnsServers(dnsServer);
  ArrayList ar = dns.getMXRecords("daum.net");  //얻어오고자 하는 메일 주소

  IEnumerator ie = ar.GetEnumerator();

  while(ie.MoveNext())
   Console.Out.WriteLine(((MXRecord)ie.Current));

  Console.ReadLine();

 

 

출처 : http://www.dotnet247.com/247reference/a.aspx?u=http://www.csharphelp.com/archives/files/archive43/DnsLite.cs

'programming > c#' 카테고리의 다른 글

COM+에 assembly를 등록하는데는 3가지 방법  (0) 2004.11.09
[펌] 바이트자르기  (0) 2004.10.01
[펌] Threading in C# and .NET  (0) 2004.10.01
>>>문자열 String형을 charcter 단위가 아닌 byte단위로 제어할수있나요?
>>>1바이트나 2바이트문자가 섞여있는 문자열을 제어하고 싶은데...
>>>String 의 메소드에는 character의 크기만가지고 하는것 같더라구요.
>>
>>String str = "우리나라 korea";
>>byte[] byteArray = str.getBytes();
>>위의 방식을 원하시나요 ?
>
>
>위에서처럼 하면 byteArray 를  1바이트 다뉘로 제어가 가능한지요.
>저는 한글전각2바이트문자를 1바이트단위로 제어를 하고 싶어서 그러거든요.
>예를 들어
>
>String str = "ABCD가나다라";
>
>에서 "ABCD"는 1바이트문자(총 4바이트) "가나다라"는 2바이트문자(총 8바이트)라면
>전체문자열의 총 바이트수라던가 처음부터 n번째 바이트까지 문자열을 짤라맨다던가 하는걸 할 수도 있나요?

// 이정도면 답이 될수 있을까요 ?
String str = "우리나라 Corea";
byte[] byteArray = str.getBytes();
System.out.println(byteArray.length);
byteArray[9] = (byte)'K';
System.out.println(new String(byteArray, "KSC5601"));
byte[] nation = new byte[10];
for(int i=9; i<=13; i++)
{
  nation[i-9] = (byte)byteArray[i];
}
System.out.println(new String(nation, "KSC5601"));

Threading in C# and .NET

Welcome to Multithreading programming section of C# Corner. In this section, you will find various multithreading related source code samples, articles, tutorials, and tips. If you have some cool code, article, white paper, or tips related to Windows Forms and want to share with other peer developers, send it to webmaster@c-sharpcorner.com.
Source Code
Multithreaded XML Document for Read/Write Access by John Bailo. July 21, 2004.
This article describes a process for using a ThreadPool within a windows service that monitors other services. It also shows how to allow multithreaded read/write access to an XmlDocument, that acts as persistent storage, using a Mutex.
Performing Lengthy Operations on a Single Thread in .NET Applications by Wiktor Zvchla. July 08, 2004.
In this article I discuss how the lenghty operations can be handled in a .NET application. I also discuss how the stack trace can be examined to find any specific methods.
Interlocking Threads by Mahesh Chand. Sep 10, 2003.
Sharing variables among multiple concurrent threads may lead to data inconsistency. To overcome data inconsistency, we usually apply locking mechanism on the shared variables. However, locking may not be the best way in some cases.
Changing the default limit of 25 threads of ThreadPool class  by Yash Malge. Jun 19, 2003.
The thread pool is created the first time you create an instance of the ThreadPool class. 
Use Thread Local Storage to Pass Thread Specific Data by Doug Doedens.  Mar 18, 2003.
In an ideal world developers typically create instance variables and access these via interfaces to hold thread specific data.
ChessyOnline Version 1.0  by Samesh Ahmad.  Dec 31, 2002.
The attached project is a chess game that can be played by two users online as well as on the network. 
Synchronized Threading in .NET by Ahmad Al-Kayali. Dec 11, 2002.
Threads are a powerful abstraction for allowing parallelized operations: graphical updates can happen while another thread thread is performing computations, two threads can handle two simultaneous network requests from a single process, and the list goes on. Since threads are pretty simple to understand, conceptually, but, practically, they are a cause for programmatic headaches, I decided to write this program to describe how to make use of threads. 
Using the ThreadPool to Run Animated Gifs by Mike Gold. Nov 14, 2002.
In this article we will discuss the use of the ThreadPool class in conjunction with the ImageAnimator class to run 3 animated gifs in separate threads. 
Sorting using Multithreading by Indika M. W. Nov 13, 2002.
This is simple multithreading application that sort integers values in an array. 
Client Server Multuthreaded Application  by Indika M. W. Nov 08, 2002.
This is simple Client/Server (multi-threading) program that transfers data. Server can handle multiple clients. 
Consumer/Producer Multithreaded Application by Indika M. W. Nov 04, 2002.
This is consumer/producer multi-threading program written in C#. 
Drawing Shapes Using Threading by Indika M.W . Oct 25, 2002.
This is simple multi-threading program that draws circles and rectangles. 
Recipe to Implement Threads Quick n' Easy in C# by Erlend Larson. Aug 28, 2002.
In this tutorial type article, author shows how to write threading applications quick and easy in C#.
Loading XML Document in a TreeView Control by Manisha Mehta. Apr 29, 2002.
There are many occasions when programmers need to develop multithreading applications, which can load big files in the background and let the user do data entry or other jobs without any interruption. In this article, I'll show you how to create multiple threads to load multiple files.  
Multi-threading Web Applications: Part II - Port Scanner by Tin Lam. Mar 12, 2002.
In this article, I will demonstrate how you can apply the same technique to a web based port scanner.
Multi-threading Web Applications: Part I - Search Engine by Tin Lam. Mar 07, 2002.
Multi-threading is the ability for an application to perform more than one execution simultaneously. 
Messaging between threads using Message Looping by John Schofield. Aug 22, 2001.
MessageLoopLib is a stripped down version of a complete, threading communication subsystem I?ve written. 
Synchronization of Parallel Threads  by Paul Abraham. Jul 02, 2001.
The Threads makes us  able to run multitasks at a time. In fact  Computers (John von Neumann Architecture) don't  execute  the tasks parallel. The OS gives threads permission (depend on thread priority) to work on CPU. The sufficient degree of parallelism keeps the CPU busy  and it is efficient.
Synchronization in Multithreading by Hari Shanker. Feb 13, 2001.
This article with sample code shows synchronization concepts of multithreading ..
Making UI more responsive by using Threading by Hari Shanker. Feb 12, 2001.
See how threads can help us to make User interface more responsive when we have some background jobs.
Articles and Tutorials
Multithreading Part 4: The ThreadPool, Timer Class and Asynchronous Programming Discussed by Manish Mehta. Apr 16, 2002
If you were following my first three parts of this series, you probably are familiar with basics of threading
Multithreading Part 3: Thread Synchronization by Manish Mehta. Apr 11, 2002
Gradually, as you start picking up the threads of multi-threading, you would feel the need to manage shared
Multithreading Part 2: Understanding the Thread Class by Manish Mehta. Apr 08, 2002
In this article we will study the .NET threading API, how to create threads in C#, start and stop them
Multithreading Part 1: Multitasking and Multithreading by Manish Mehta. Apr 08, 2002
Gradually, as you start picking up the threads of multi-threading, you would feel the need to manage shared

'programming > c#' 카테고리의 다른 글

[펌] 바이트자르기  (0) 2004.10.01
[펌]Obtaining the HTML from a URL  (0) 2004.09.14
[펌]Using Application Configuration Files in .NET  (0) 2004.09.03

한빛 미디어에 나온 기사 스크랩입니다.

 


..more


'programming > c#' 카테고리의 다른 글

[펌] Threading in C# and .NET  (0) 2004.10.01
[펌]Using Application Configuration Files in .NET  (0) 2004.09.03
.Net API Class의 Mock Object 만들기...  (0) 2004.09.03

configuration File은 예전에 ini파일이나 레지스트리에 저장했던 정보들을 저장하는 파일이다.

자세한 내용은 아래의 기사를 확인~

 

 


..more


음...

요즘 회사에서 진행 중인 프로젝트를 XP를 도입하여 진행 중이다.

 

그래서 페어 프로그래밍이라던가 TDD를 하게 되는데, TDD를 하던 중 문제가 발생했다.

ADO.Net 프로그래밍이나 Socket을 사용하는 부분에서 그 Class들에 대한 Mock을 만들지 못하는 문제이다.

 

이러한 문제를 해결할 수 있는 방법을 아시는 분은 연락 주심 매우 고맙겠습니다. ^^''

관련 내용을 찾아다니던 중 나와 같은 문제로 고민하는 사람의 Post를 발견해서 밑에 올립니다.

 

--------

.NET Needs Better Interfaces
In this post, Frans Bouma continues his list of things he wants added to the VS.NET IDE and the .NET API.

My biggest complaint about the .NET API is that I don't think MS used interfaces enough. (And they seal classes that they shouldn't, but Frans already convered that one.) If you have tried to do TDD with Maverick.NET, for example, you very quicly run into a problem with HttpContext and the other HTTP Pipeline classes. Because there are no interfaces to be found, you can't mock them at all.

A similar problem exists in ADO.NET. Once again you can't do TDD very well with it. The root cause is that you can't really write code that is independent of your data provider. It is very close, but when you really get in there you will find that you can't create a DataAdapter without knowing whether you're doing SQL or OLEDB. (Justin wrote Abstract ADO.NET to deal with this, but he shouldn't have had to.)

Another example: Sockets. I was trading email with someone last week and he was asking me how to create a mock Socket. In Java, Socket is an interface, so MockSocket has something to derive from. In .NET, Socket is a class. It is very difficult to mock without creating your own ISocket interface and then creating a lightweight wrapper that aggregates the .NET Socket class. Very annoying.

posted on Wednesday, June 25, 2003 2:49 PM

 

출처 : http://www.peterprovost.org/archive/2003/06/25/576.aspx

내용이 많으므로 관심있는 분만 누르세요~~


..more