locked
C# to VB statement conversion RRS feed

  • Question

  • VB version

    Public Sub Install(ByVal container As IWindsorContainer, ByVal store As IConfigurationStore) Implements IWindsorInstaller.Install

                container.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient())
    End Sub

    C# version

    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient());
    }

    IController  resolves in the C# version. The VB version VS says IController is a type and cannot be used in an expression.

    How can I fix the VB version of the code?

    Thanks

    Sunday, February 16, 2014 10:34 PM

Answers

  • Hello,

    Try this

    Public Sub Install(ByVal container As IWindsorContainer, ByVal store As IConfigurationStore)
    	container.Register(Classes.FromThisAssembly().BasedOn(Of IController).LifestyleTransient())
    End Sub

    Or

    Public Sub Install(ByVal container As IWindsorContainer, ByVal store As IConfigurationStore)
    	container.Register(Classes.FromThisAssembly().BasedOn(Of IController)().LifestyleTransient())
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.



    Sunday, February 16, 2014 10:52 PM

All replies

  • Hello,

    Try this

    Public Sub Install(ByVal container As IWindsorContainer, ByVal store As IConfigurationStore)
    	container.Register(Classes.FromThisAssembly().BasedOn(Of IController).LifestyleTransient())
    End Sub

    Or

    Public Sub Install(ByVal container As IWindsorContainer, ByVal store As IConfigurationStore)
    	container.Register(Classes.FromThisAssembly().BasedOn(Of IController)().LifestyleTransient())
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.



    Sunday, February 16, 2014 10:52 PM
  • BasedOn(Of IController) worked!

    Thanks and I'll mark your answer as the answer.

    Sunday, February 16, 2014 11:32 PM
  • @Kevininstructor

    I am at a lost as to why the conversion of the Castel Windsor IoC  code when converted over to VB.NET in the link provided doesn't work.

    The problem is that the below method based on creating concrete classes  from the IController flatout doesn't work.  The container has errors in it when viewed in Quickwatch,  and no controller objects are in the container.

    All of it works in C# with no problems on the Unit Tests for the Controllers with Castel Windsor.

    If Unit Tests do not pass, then trying to use the code for real when running the MVC solution is a failure and exceptions thrown.

    I don't know. Maybe I am missing something. But the IoC should work in VB as easily as it does in C#.

    Maybe, you can look at and see if something needs to be in place on the VB side that I am missing. I have implemented the IoC in a C# enterprise production MVC4 solution. I am hoping to do the same with VB. This is ridiculous that the IoC is not working in VB. 

     http://docs.castleproject.org/Windsor.Windsor-tutorial-ASP-NET-MVC-3-application-To-be-Seen.ashx

    http://docs.castleproject.org/Default.aspx?Page=MainPage&NS=Windsor&AspxAutoDetectCookieSupport=1

    Imports System.Web.Mvc
    Imports Castle.MicroKernel.Registration
    Imports Castle.MicroKernel.SubSystems.Configuration
    Imports Castle.Windsor

    Namespace Installers
        Public Class ControllerInstaller
            Implements IWindsorInstaller

            Public Sub Install(ByVal container As IWindsorContainer, ByVal store As IConfigurationStore) Implements IWindsorInstaller.Install
                container.Register(Classes.FromThisAssembly().BasedOn(Of IController)().LifestyleTransient())
            End Sub
        End Class
    End Namespace

    Monday, February 17, 2014 9:23 PM
  • dagnabbit I did a reply then it went puff.

    Okay, I'd go wit Occam's Razor, which states that among competing hypotheses, the hypothesis with the fewest assumptions should be selected.

    Thoughts:

    • Is there a permission issue, does the app have full trust (can't hurt to try just to see) ?
    • Never used this library so I would ask (as I have been bitten in WCF this way), are there any manatory settings that must be in place in a config file or the web config file?
    • Try going from ByVal to ByRef, can't hurt to try altough I doubt this will fix it.
    • Have you tried coding is a solution with the least amount of code to test this?

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Monday, February 17, 2014 10:47 PM
  • I already have a MVC4 C# solution using Windsor Castle IoC that is using the same UT code on my development machine. It works perfectly with no problems. Not only do the UT's pass,  but the C# solution works perfectly in using the IoC.

    So I wanted to duplicate the solution and convert it over to VB, and the same code I have converted to use VB just flatout doesn't work in the IoC area. I can go into debug mode on both solutions (C# and VB) and clearly see the objects are correct in C#, but they are in error when using VB.

    It makes no sense, because the IoC code for Castel Windsor DLL's should work the same no matter what .Net  language VB or C# is using the IoC solution.  The sad thing is that I can find no forum on Castle Windsor to post questions as to what is happening when the IoC is used in a VB.NET solution. :(  

     
    Tuesday, February 18, 2014 12:03 AM
  • I too looked for support forums or VB.NET questions out there similar to you and think that is sad too that VB.NET developers are not working with Castle.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Tuesday, February 18, 2014 12:07 AM
  • Yes, it is unfortunate that a developer that knows VB and C# can't find tutorials and howto(s) in VB as easily as they can be found in C#. It makes no sense to me why this is this way, but those are the sad facts.
    Tuesday, February 18, 2014 10:08 AM