Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert C# StructureMap initialization to VB.NET?

I'm about to put my head thru this sliding glass door. I can't figure out how to execute the following code in VB.NET to save my life.

private static void InitStructureMap()
    {
        ObjectFactory.Initialize(x =>
                                     {
                                         x.AddRegistry(new DataAccessRegistry());
                                         x.AddRegistry(new CoreRegistry());
                                         x.AddRegistry(new WebUIRegistry());

                                         x.Scan(scanner =>
                                                    {
                                                        scanner.Assembly("RPMWare.Core");
                                                        scanner.Assembly("RPMWare.Core.DataAccess");
                                                        scanner.WithDefaultConventions();
                                                    });
                                     });
    }
like image 849
Kyle West Avatar asked Dec 18 '22 09:12

Kyle West


1 Answers

At the moment, it's simply not possible. The current version of VB does not support multiline (or statement) lambdas. Each lambda can only comprise one single expression. The next version of VB will fix that (there simply wasn't enough time in the last release).

In the meantime, you'll have to make do with a delegate:

Private Shared Sub Foobar(x As IInitializationExpression)
    x.AddRegistry(New DataAccessRegistry)
    x.AddRegistry(New CoreRegistry)
    x.AddRegistry(New WebUIRegistry)
    x.Scan(AddressOf Barfoo)
End Sub

Private Shared Sub Barfoo(ByVal scanner As IAssemblyScanner) 
    scanner.Assembly("RPMWare.Core")
    scanner.Assembly("RPMWare.Core.DataAccess")
    scanner.WithDefaultConventions
End Sub

' … '
ObjectFactory.Initialize(AddressOf Foobar)
like image 192
Konrad Rudolph Avatar answered Dec 24 '22 01:12

Konrad Rudolph