Reputation: 328
I have installed
SharpRepository.EfRepository
SharpRepository.Ioc.Autofac
SharpRepository.Repository
and I have added this code to setup Autofac as instructed by the Autofac documentation:
void SetupAutofac()
{
var builder = new ContainerBuilder();
// Get your HttpConfiguration.
HttpConfiguration config = GlobalConfiguration.Configuration;
// Register your Web API controllers.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
// OPTIONAL: Register the Autofac filter provider.
builder.RegisterWebApiFilterProvider(config);
// Set the dependency resolver to be Autofac.
IContainer container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
but the SharpRepository getting started guide doesn't help me with the Autofac --> EF --> SharpRepo glue stuff as it's oriented towards StructureMap. Please advice!
(I'd like to avoid putting stuff in Web.config if possible)
Upvotes: 1
Views: 212
Reputation: 13510
You will need to install the SharpRpository.Ioc.Autofac NuGet package, if you haven't.
Then you will call
builder.RegisterSharpRepository()
in order to tell Autofac how to handle an IRepository.
Then to tell SharpRpository to use Autofac when it needs EF you will need to call
RepositoryDependencyResolver.SetDependencyResolver(new AutofacDependencyResolver(container));
That should do it.
Upvotes: 2