在VB.Net中使用Web窗体进行Autofac抛出MissingMemberException

时间:2014-03-11 16:17:57

标签: asp.net vb.net webforms autofac

我正在尝试使用vb.net在我的Web窗体应用程序中使用Autofac,我正在关注Autofac网站中的示例,但我收到此错误:

类型' System.MissingMemberException'的例外情况发生在Microsoft.VisualBasic.dll但未在用户代码中处理。 附加信息:公共成员' RegisterType'在类型' ContainerBuilder'没找到。

这是我在Global.asax.vb中定义的内容:

Shared _containerProvider As IContainerProvider

Public ReadOnly Property ContainerProvider() As IContainerProvider Implements IContainerProviderAccessor.ContainerProvider
        Get
            Return _containerProvider
        End Get
    End Property

...

' Build up your application container and register your dependencies.
Dim builder = New ContainerBuilder()
builder.RegisterType(Of CustomerService)().As(Of ICustomerService)()
builder.RegisterType(Of CustomerContactService)().As(Of ICustomerContactService)()
builder.RegisterType(Of UnitOfWork)().As(Of IUnitOfWork)()


' Once you're done registering things, set the container
' provider up with your registrations.
_containerProvider = New ContainerProvider(builder.Build())

这就是我在web.config中的内容:

<system.webServer>
    <modules>
      <add name="ContainerDisposal" type="Autofac.Integration.Web.ContainerDisposalModule, Autofac.Integration.Web" preCondition="managedHandler"/>
      <add name="PropertyInjection" type="Autofac.Integration.Web.Forms.PropertyInjectionModule, Autofac.Integration.Web" preCondition="managedHandler"/>
      <add name="AttributedInjection" type="Autofac.Integration.Web.Forms.AttributedInjectionModule, Autofac.Integration.Web" preCondition="managedHandler"/>
    </modules>
</system.webServer>

<httpModules>
  <!-- This section is used for IIS6 -->
  <add name="ContainerDisposal" type="Autofac.Integration.Web.ContainerDisposalModule, Autofac.Integration.Web"/>
  <add name="PropertyInjection" type="Autofac.Integration.Web.Forms.PropertyInjectionModule, Autofac.Integration.Web"/>
  <add name="AttributeInjection" type="Autofac.Integration.Web.Forms.AttributedInjectionModule, Autofac.Integration.Web"/>
</httpModules>

我通过nuget Autofac.Web

添加了所有引用

我做错了什么?

1 个答案:

答案 0 :(得分:1)

尝试将Dim builder = New ContainerBuilder()更改为Dim builder As ContainerBuilder = New ContainerBuilder()

编译器无法识别您正在调用没有强类型的扩展方法。

  

延迟绑定不考虑扩展方法。

MSDN: Extension Methods (Visual Basic)