gpt4 book ai didi

c# - ServiceInterface 中的 ServiceStack Ormlite 使用

转载 作者:行者123 更新时间:2023-11-28 23:42:37 25 4
gpt4 key购买 nike

我已经使用空的 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);

我无法弄清楚的是如何访问 ServiceInterface 项目中包含 Save() 的 OrmliteWriteExtensions。我尝试在那里添加 Ormlite 和 MySql,但不知道如何访问该项目中 connectionfactory 的引用。

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

建议?

TIA

最佳答案

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

关于c# - ServiceInterface 中的 ServiceStack Ormlite 使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34114080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com