Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6194599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:19:26+00:00 2026-05-24T03:19:26+00:00

Currently my code has the following properties: Private _queueRetriever As Services.IQueueRetriever Public ReadOnly Property

  • 0

Currently my code has the following properties:

  Private _queueRetriever As Services.IQueueRetriever
  Public ReadOnly Property QueueRetriever As Services.IQueueRetriever
     Get
        If _queueRetriever Is Nothing Then
           RemotingSetup.RegisterHttpBinaryChannel()
           _queueRetriever = RemotingFactory.CreateProxy(Of Services.IQueueRetriever)(Options.DevLocal)
        End If

        Return _queueRetriever
     End Get
  End Property

  Private _queueCountRetriever As Services.IQueueCounter
  Public ReadOnly Property QueueCounter As Services.IQueueCounter
     Get
        If _queueCountRetriever Is Nothing Then
           RemotingSetup.RegisterHttpBinaryChannel()
           _queueCountRetriever = RemotingFactory.CreateProxy(Of Services.IQueueCounter)(Options.DevLocal)
        End If

        Return _queueCountRetriever
     End Get
  End Property

As you can see, the code is essentially the same for both properties. Only the types are different. I’m not very experienced in generic methods, but I feel like I should be able to make this code more DRY using generics. Can it be done or is this not a job for generic methods?

EDIT

Building on Marc’s answer, I came up with the following:

  Protected Services As New Dictionary(Of Type, Object)

  Protected Function CreateService(Of T)() As T
     If Not Services.ContainsKey(GetType(T)) Then

        RemotingSetup.RegisterHttpBinaryChannel()
        Services.Add(GetType(T), RemotingFactory.CreateProxy(Of T)(Options.DevLocal))

     End If

     Return DirectCast(Services(GetType(T)), T)
  End Function

Which, of course, can be used like so:

Me.CreateService(Of IService).Foo()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:19:27+00:00Added an answer on May 24, 2026 at 3:19 am

    You could do (and apologies for switching into C#, but my VB skills lack the subtlety here – I’m sure it works fine in VB too though)

    private T GetProxy<T>(ref T field) where T : class {
        if(field == null) {
            RemotingSetup.RegisterHttpBinaryChannel();
            field = RemotingFactory.CreateProxy<T>(Options.DevLocal);
        }
        return field;
    }
    

    with:

    private Services.IQueueCounter queueCounter;
    public Services.IQueueCounter QueueCounter {
        get { return GetProxy(ref queueCounter); }
    }
    private Services.IQueueRetriever queueRetriever;
    public Services.IQueueRetriever QueueRetriever {
        get { return GetProxy(ref queueRetriever); }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code currently looks like this: private Foo myFoo; public Foo CurrentFoo { get
I currently have code that does the following: private final static ExecutorService pool =
Has anyone managed to get the transfer mechanism working with FILESTREAM columns? My code
In the Groovy console, the following code executes without error: class F { private
I have a property Foo on a class Bar: public int Foo { get
In my current code, a user has a list of goals he has joined.
The Chinese currency has the ISO 4217 code CNY. Since free global trading in
Currently my code below works fine but it's a bit of overkill. In my
Currently my code loads a TabWidget with 4 tabs. The first tab points to
Currently our code uses a for-loop for filling a buffer holding a Unicode string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.