简体   繁体   English

ServiceInterface中ServiceStack Ormlite的用法

[英]ServiceStack Ormlite usage in ServiceInterface

I have created a solution using the empty asp.net template. 我使用空的asp.net模板创建了一个解决方案。 I have addred Ormlite and MySql Servicestatck libraries and configured them in the Apphost.cs 我添加了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);

What I am having trouble figuring out is how to access the OrmliteWriteExtensions which include Save() in the ServiceInterface project. 我遇到的麻烦是如何访问OrmliteWriteExtensions,其中包括ServiceInterface项目中的Save()。 I tried adding Ormlite and MySql there but don't know how to access the reference of the connectionfactory in this project. 我尝试在其中添加Ormlite和MySql,但不知道如何在该项目中访问connectionfactory的引用。

I think my issue relates to a lack of deeper understanding of IoC I am probably over complicating something here. 我认为我的问题与对IoC缺乏更深入的了解有关,我可能在这里使事情变得复杂了。

Suggestions? 建议?

TIA TIA

Thank you for the feedback. 感谢您的反馈。 I wish to thank you for such a fantastic library. 我要感谢您拥有如此出色的图书馆。 My issues turns out was my lack of understanding of IoC and I had to do code like: var conn = HostContext.Container.Resolve<IDbConnection>(); conn.Open(); conn.Save<Channel>(channel); 我的问题原来是我对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