我使用空的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
答案 0 :(得分:1)
感谢您的反馈。我想感谢你这么棒的图书馆。我的问题结果是我对IoC缺乏了解,我不得不做如下代码:var conn = HostContext.Container.Resolve<IDbConnection>();
conn.Open();
conn.Save<Channel>(channel);
答案 1 :(得分:0)
OrmLite扩展方法位于ServiceStack.OrmLite
命名空间下,因此只需要导入即可访问它们:
using ServiceStack.OrmLite;