Unity.MVC Nuget Package - VB.NET Version?

Jul 9, 2013 at 10:20 AM
Is there a VB version of the Unity bootstrapper for ASP.NET MVC package?

Installing the Unity nuget package got me the vb.net files installed, but the Unity.Mvc package dropped two C# files into my project which obviously won't work.

Any information would be gratefully received.

Cheers,
Nick
Jul 11, 2013 at 6:27 AM
I don't believe there are formal VB.NET versions.

There's not much code so you could convert the C# to VB.NET.

UnityConfig.vb:
Imports Microsoft.Practices.Unity
Imports Microsoft.Practices.Unity.Configuration

Namespace UnityAspNetMvcBootstrapper.App_Start
    ''' <summary>
    ''' Specifies the Unity configuration for the main container.
    ''' </summary>
    Public Class UnityConfig
        #Region "Unity Container"
        Private Shared container As New Lazy(Of IUnityContainer)(Function() 
        Dim container = New UnityContainer()
        RegisterTypes(container)
        Return container

End Function)

        ''' <summary>
        ''' Gets the configured Unity container.
        ''' </summary>
        Public Shared Function GetConfiguredContainer() As IUnityContainer
            Return container.Value
        End Function
        #End Region

        ''' <summary>Registers the type mappings with the Unity container.</summary>
        ''' <param name="container">The unity container to configure.</param>
        ''' <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to 
        ''' change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        Public Shared Sub RegisterTypes(container As IUnityContainer)
            ' NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
            ' container.LoadConfiguration();

            ' TODO: Register your types here
            ' container.RegisterType<IProductRepository, ProductRepository>();
        End Sub
    End Class
End Namespace
UnityMvcActivator.vb:
Imports System.Linq
Imports System.Web.Mvc
Imports Microsoft.Practices.Unity.Mvc

<Assembly: WebActivatorEx.PreApplicationStartMethod(GetType(UnityAspNetMvcBootstrapper.App_Start.UnityWebActivator), "Start")>

Namespace UnityAspNetMvcBootstrapper.App_Start
    ''' <summary>Provides the bootstrapping for integrating Unity with ASP.NET MVC.</summary>
    Public NotInheritable Class UnityWebActivator
        Private Sub New()
        End Sub
        ''' <summary>Integrates Unity when the application starts.</summary>
        Public Shared Sub Start()
            Dim container = UnityConfig.GetConfiguredContainer()

            FilterProviders.Providers.Remove(FilterProviders.Providers.OfType(Of FilterAttributeFilterProvider)().First())
            FilterProviders.Providers.Add(New UnityFilterAttributeFilterProvider(container))

            DependencyResolver.SetResolver(New UnityDependencyResolver(container))

            ' TODO: Uncomment if you want to use PerRequestLifetimeManager
            ' Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
        End Sub
    End Class
End Namespace
I did a quick test and it seemed to run OK.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to