实施Windsor,迁移并提出问题

时间:2013-07-11 23:23:42

标签: asp.net-mvc castle-windsor linkedin ioc-container

我最近在一个新的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"])));

然后我设置了一个实现LinkedInServiceILinkedInService

的静态对象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

感到茫然

任何帮助?

1 个答案:

答案 0 :(得分:1)

除了在容器中注册创建的实例外,您无需执行任何操作:

Kernel.Register(Component.For<ILinkedInService>()
    .Instance(LinkedInServiceHelper.LinkedInService)));