我使用Drum它提供了一個通用類`UriMaker:如何使用Simple Injector註冊Drum.UriMaker <>?
public class UriMaker<TController>
{
// I need use this one
public UriMaker(UriMakerContext context, HttpRequestMessage request) { }
public UriMaker(Func<MethodInfo, RouteEntry> mapper, UrlHelper urlHelper) { }
}
像這樣來使用:
public class UserController : ApiController
{
public UserController(UriMaker<UserController> urlMaker) {}
}
我已經使用統一進行註冊:
container.RegisterType(typeof(UriMaker<>),
new InjectionConstructor(typeof(UriMakerContext), typeof(HttpRequestMessage)));
但現在正在遷移到Simple Injector。我已經有這個了:
UriMakerContext uriMaker = config.MapHttpAttributeRoutesAndUseUriMaker();
container.RegisterSingle(uriMakerContext);
那麼現在如何註冊UriMaker<>
本身?
這真是太棒了,謝謝!同時我找到了這個解決方案:http://pastebin.com/LhidzEVF。我更喜歡你,因爲它至少涉及更少的新課程。並有助於避免直接注入外部組件。 – abatishchev 2014-10-30 22:59:51
@abatishchev:是的,你的解決方案是我在第一行的答案中勸阻的解決方案:-) – Steven 2014-10-30 23:13:55
是的,確切地說,謝謝你的推理:) – abatishchev 2014-10-31 00:04:57