나는 엄격한 IoC 패턴을 따르고 나쁜 습관에 빠지지 않도록 노력하고 있습니다.이 코드는 IoC를 올바르게 사용합니까? 여기서 어디로 갈 수 있습니까?
회원 클래스의 생성자에 관련 정보를 모두로드해야합니까?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Xml.Linq;
using SharpDIC.Api.Interfaces;
using SharpDIC.Api.Models;
using System.Configuration;
namespace SharpDIC.Api.Concrete
{
class XmlMemberFinder : IMemberFinder
{
public IList<Member> FindAllMembers()
{
using (var webClient = new WebClient())
{
for (int i = 0; i < 470000; i++)
{
string htmlSource = webClient.DownloadString(ConfigurationManager.AppSettings["MemberUrl"] + i);
XDocument response = XDocument.Parse(htmlSource);
//The member class would parse the XML itself and load it's attributes itself.
Member member = new Member(response);
}
}
}
public Member FindMember(int memberId)
{
throw new NotImplementedException();
}
public Member FindMember(string memberName)
{
throw new NotImplementedException();
}
}
}
당신은 무엇을 할 것? 이것이 가능한 TDD/IoC를 유지하기위한 가장 좋은 해결책은 무엇입니까?
편집 :
괜찮습니까?
using SharpDIC.Api.Models;
namespace SharpDIC.Api.Interfaces
{
interface IMemberSource
{
Member LoadMember(string source);
}
}
내가 다시 붙어있어, 실제로 뭔가를로드합니까? 실제로 뭔가 작업을하지 않고 인터페이스를 만든 후에 인터페이스를 작성하는 것처럼 느껴집니다.
- 그것은에 조금 걸립니다 그 주위에 머리를 얻을. 당신은 옳은 길을 가고 있습니다 만, LoadMember()는 '소스'를 알지 않아야합니다 - 그것을 구현하는 객체도 마찬가지입니다. 첫 번째 코드 블록에서도 config 문자열을 쿼리하여 소스를 가져옵니다. IMemberSource의 프로덕션 구현도 똑같이 할 것입니다. LoadMember는 아마도 인수가 필요하지 않거나 열거 형을 반환 할 수 있습니까? – n8wrl
이것에 대해 더 생각해보십시오. IMemberSource는 실제로 저장소입니다. DB, XML/웹 서비스, 테스트 용 하드 코딩 된 콜렉션 등 어떤 소스에서 멤버를 얻는 방법을 알고있는 것입니다. – n8wrl
@ n8wrl : 의견을 보내 주셔서 감사합니다. 시간이 걸릴 것입니다. :) 나는이 특별한 문제를 해결했다고 생각한다. 나는 일을 올바르게하고 싶습니다. :피 –