0

I'm trying to figure out the syntax to inject OrmLiteConnectionFactory using AutoFac. This is a working example using Funq, another DI framework.

container.Register<IDbConnectionFactory>(c => 
OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["AppDb"].
    ConnectionString, SqlServerDialect.Provider);
Gray
  • 115,027
  • 24
  • 293
  • 354
Shane
  • 4,185
  • 8
  • 47
  • 64

1 Answers1

3

Try this:

container.Register(c => 
        new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["AppDb"].ConnectionString,
                SqlServerDialect.Provider)).As<IDbConnectionFactory>();
Peter Lillevold
  • 33,668
  • 7
  • 97
  • 131
Memoizer
  • 2,231
  • 1
  • 14
  • 14
  • Most of this syntax works except for the last part: .As() shows this error in intellisense: Error 14 Using the generic method 'Autofac.RegistrationExtensions.As(Autofac.Builder.IRegistrationBuilder, System.Func>)' requires 3 type arguments – Shane May 11 '13 at 18:30
  • @Shane - you get the error due to a missing parenthesis. I have fixed Memoizers sample. – Peter Lillevold May 11 '13 at 22:24