Configuring MicroLite

One of the principles behind the MicroLite framework is that it should be as simple as possible to configure.

There are only 2 things you need to do to configure MicroLite, the first is to add a named connection string to the app.config (or web.config).

<connectionStrings>
    <add name="NorthwindDB"
         connectionString="Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=False;Integrated Security=SSPI;"
         providerName="System.Data.SqlClient" />
</connectionStrings>

Then, in your application start-up you need to call the configuration class to create the session factory for the database you wish to use.

using MicroLite;
using MicroLite.Configuration;

static void Main(string[] args)
{
    var sessionFactory = Configure
        .Fluently()
        .ForConnection("NorthwindDB") // The name provided here should match the name in the app.config
        .CreateSessionFactory();

    ...
}

Once you have created a session factory, you can either store it in a static property which makes it visible to your application, or ideally register it in an IOC container.

This article was written for version 1.2.2 of the MicroLite framework.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s