我想知道如何从我的全球过滤器中访问IDbConnection,到目前为止我拥有的是这个。
现在,我越多地思考这个问题,我就不会在我的apphost中使用IDb的东西,那么我如何才能检索我的存储库,该存储库封装了可能的东西和缓存呢?
谢谢你,斯蒂芬
Global.asax
public override void Configure(Container container)
{
var dbConnectionFactory =
new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("test"), true, SqlServerOrmLiteDialectProvider.Instance);
container.Register<IDbConnectionFactory>(dbConnectionFactory);
RequestFilters.Add((httpReq, httpResp, requestDto) =>
{
// Do something here with either my repo or ormLite
});
}发布于 2013-04-09 22:20:59
如果您已经访问了容器,您可以这样做:
RequestFilters.Add((httpReq, httpResp, requestDto) => {
using (var db = container.Resolve<IDbConnectionFactory>().Open())
{
// Do something here with either my repo or ormLite
}
});否则,您可以通过AppHostBase.Resolve<T>单例访问它:
RequestFilters.Add((httpReq, httpResp, requestDto) => {
using (var db = AppHostBase.Resolve<IDbConnectionFactory>().Open())
{
// Do something here with either my repo or ormLite
}
});https://stackoverflow.com/questions/15912972
复制相似问题