我最近在一个新的MVC项目上实现了Windsor(两者都是新的)并且无法用它实现服务。
该服务是small toolkit project for linkedin that uses c#。在提供的示例中,可以像这样设置服务:
在App_Start / AuthConfig.cs中,我创建了一个linkedInOAuthClient
的新实例,这是使用该工具包的主要对象。
LinkedInOAuthClient linkedInOAuthClient = new LinkedInOAuthClient(new CookieAccessTokenStorage(ConfigurationManager.AppSettings["apiSecret"]),
new DotNetOpenAuthWebConsumer(ServiceDescriptions.Authenticate,
new InMemoryOAuthTokenManager(ConfigurationManager.AppSettings["apiKey"], ConfigurationManager.AppSettings["apiSecret"])));
然后我设置了一个实现LinkedInService
到ILinkedInService
linkedInOAuthClient
LinkedInServiceHelper.LinkedInService = linkedInOAuthClient;
然后在我的控制器中
public ILinkedInService LinkedInService { get; set; }
public HomeController(ILinkedInService linkedInService)
{
LinkedInService = linkedInService;
}
以便使用该服务。
我的问题是:我如何迁移LinkedInService以使用Windsor?
我已经将LinkedInService注册为设施并将其安装在Windsor
中public class LinkedInFacility : AbstractFacility
{
protected override void Init()
{
Kernel.Register(Component.For<ILinkedInService>()
.ImplementedBy<LinkedInOAuthClient>().LifestyleTransient());
}
}
但我对如何实施linkedInOAuthClient
任何帮助?
答案 0 :(得分:1)
除了在容器中注册创建的实例外,您无需执行任何操作:
Kernel.Register(Component.For<ILinkedInService>()
.Instance(LinkedInServiceHelper.LinkedInService)));