[VB.NET] Unity Register All Form

Nguyen Minh 1 Reputation point

Hi all,

I have something like this when try to register all type without specify each class (using AllClasses, WithMappings from Unity.RegistrationByConvention ):

Dim injections As IEnumerable(Of InjectionMember) = New List(Of InjectionMember) From {
         New Interceptor(Of InterfaceInterceptor),
         New InterceptionBehavior(Of PolicyInjectionBehavior)

Dim allTypes = AllClasses.FromAssemblies(GetType(MyBaseService).Assembly)
unity.RegisterTypes(allTypes, AddressOf WithMappings.FromMatchingInterface, getInjectionMembers:=Function(t) injections)

It works so far. But when I try the same thing to register with all Form:

Dim allForm = AllClasses.FromAssemblies(GetType(Form).Assembly)
unity.RegisterTypes(allForm, AddressOf WithMappings.None, getInjectionMembers:=Function(t) injections)

There is an Exception:

ArgumentException: Type passed must be an interface.

Currently, I have to register for each Form like this:
unity.RegisterType(Of MyFormA)
unity.RegisterType(Of MyFormB)

Is there anyway I could register all form without specify each of them ?

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,558 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Duane Arnold 3,211 Reputation points

    I guess if you used the MVP UI design pattern that implements an Interface for each form, you could instance the forms with unity all at once through the IoC.


    I suggest that you watch all the shows and get a basic understanding before you try to implement the Windows form VB.NET usage of MVP.


    Other than that, I don't see how you can do it.

    0 comments No comments