Bud*_*Joe 2 .net configuration ioc-container inversion-of-control unity-container
在这篇Autofac IoC 文章中,他们展示了一个使用参数将接口映射到实现的示例.你会发现它在文章的中间.
什么是XML中的Unity等价物?不能使用流畅的语法来做我正在做的事情.需要是一个外部配置文件.
更新:
这是我想知道在Unity中如何做的特定代码 -
<component id="DataStoreProvider"
service="Company.Server.IDataStoreProvider,Company.Server.Interface"
type="Company.Server.DataStoreProvider,Company.Server.Core">
<parameters>
<connectionString>My Connection String</connectionString>
</parameters>
</component>
Run Code Online (Sandbox Code Playgroud)
也许不是以这种方式传递连接字符串的最好的例子......但是你明白了.我想知道如何在Unity中用XML做参数.
你可以做到这一点.请参阅此MSDN文章
<configuration>
<configSections>
...
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
...
</configSections>
...
<unity>
<typeAliases>
<!-- Lifetime manager types -->
<typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="external" type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="ILoginService" type="Company.Shared.ILoginService,Company.Shared.Interface" />
<typeAlias alias="LoginService" type="Company.Server.LoginService,Company.Server.Core" />
<typeAlias alias="INavigationService" type="Company.Shared.INavigationService,Company.Shared.Interface" />
<typeAlias alias="NavigationService" type="Company.Server.NavigationService,Company.Server.Core" />
</typeAliases>
<containers>
<container name="Services">
<types>
<type type="ILoginService" mapTo="LoginService" />
<type type="INavigationService" mapTo="NavigationService" />
</types>
</container>
</containers>
</unity>
....
Run Code Online (Sandbox Code Playgroud)
更新:如果您查看MSDN文章,有一节描述了我认为符合您要求的内容.
<type type="IMyService" mapTo="MyDataService" name="DataService">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement,
Microsoft.Practices.Unity.Configuration">
<constructor>
<param name="connectionString" parameterType="string">
<value value="AdventureWorks"/>
</param>
<param name="logger" parameterType="ILogger">
<dependency />
</param>
</constructor>
</typeConfig>
</type>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1420 次 |
最近记录: |