繁体   English   中英

ServiceInterface中ServiceStack Ormlite的用法

[英]ServiceStack Ormlite usage in ServiceInterface

我使用空的asp.net模板创建了一个解决方案。 我添加了Ormlite和MySql Servicestatck库,并在Apphost.cs中对其进行了配置

        ConnectionStringSettings connstring = ConfigUtils.GetConnectionStringSetting("Nice2NoConnection");
        container.Register<IDbConnectionFactory>(new OrmLiteConnectionFactory(connstring.ToString(), MySqlDialectProvider.Instance));


        // Below we refer to the connection factory that we just registered
        // with the container and use it to create our table(s).
        using (var db = container.Resolve<IDbConnectionFactory>().Open())
        {
            // We’re just creating a single table, but you could add
            // as many as you need.  Also note the “overwrite: false” parameter,
            // this will only create the table if it doesn’t already exist.
            db.CreateTable<Channel>(overwrite: false);

我遇到的麻烦是如何访问OrmliteWriteExtensions,其中包括ServiceInterface项目中的Save()。 我尝试在其中添加Ormlite和MySql,但不知道如何在该项目中访问connectionfactory的引用。

我认为我的问题与对IoC缺乏更深入的了解有关,我可能在这里使事情变得复杂了。

建议?

TIA

感谢您的反馈。 我要感谢您拥有如此出色的图书馆。 我的问题原来是我对IoC缺乏了解,我不得不执行以下代码: var conn = HostContext.Container.Resolve<IDbConnection>(); conn.Open(); conn.Save<Channel>(channel); var conn = HostContext.Container.Resolve<IDbConnection>(); conn.Open(); conn.Save<Channel>(channel);

OrmLite扩展方法位于ServiceStack.OrmLite命名空间下,因此只需导入即可访问它们:

using ServiceStack.OrmLite;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM