我已经安装
SharpRepository.EfRepository
SharpRepository.Ioc.Autofac
SharpRepository.Repository
并且我已按照 Autofac 文档的说明添加了此代码来设置 Autofac:
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);
}
但是 SharpRepository 入门指南对 Autofac --> EF --> SharpRepo 胶水没有帮助,因为它面向 StructureMap。请指教!
(如果可能的话,我想避免把东西放在 Web.config 中)