Jeff
Jeff

Reputation: 2071

ServiceStack Ormlite usage in ServiceInterface

I have created a solution using the empty asp.net template. I have addred Ormlite and MySql Servicestatck libraries and configured them in the 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. I tried adding Ormlite and MySql there but don't know how to access the reference of the connectionfactory in this project.

I think my issue relates to a lack of deeper understanding of IoC I am probably over complicating something here.

Suggestions?

TIA

Upvotes: 1

Views: 75

Answers (2)

Jeff
Jeff

Reputation: 2071

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);

Upvotes: 1

mythz
mythz

Reputation: 143389

The OrmLite extension methods are under the ServiceStack.OrmLite namespace so to access them you just need to import:

using ServiceStack.OrmLite;

Upvotes: 0

Related Questions