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 6851283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:13:45+00:00 2026-05-27T01:13:45+00:00

Morning, in the codebase i’m maintaining there is an old interface. Let’s call it

  • 0

Morning,

in the codebase i’m maintaining there is an old interface. Let’s call it IFoo. It pretty much became obsolete and replaced with the Interface INewFoo with a change a few weeks ago, but for backwards-compatibility purposes, i wrote a wrapper class which implements INewFoo and takes an IFoo in the constructor.

To clarify, consider the following code.

    Public Interface IFoo
      Sub DoStuff()
    End Interface

    Public Interface INewFoo
      Sub DoPrettyMuchTheSameStuff()
    End Interface

    Public Class FooToNewFooWrapper
      Implements INewFoo

      Private _foo As IFoo
      Public Sub New(foo As IFoo)
        _foo = foo
      End Sub

      Public Sub DoPrettyMuchTheSameStuff() Implements INewFoo.DoPrettyMuchTheSameStuff
        _foo.DoStuff()
      End Sub
    End Class

For both interfaces, the implementations are loaded by scanning a few assemblies with StructureMap.

Now, let’s get to the bad things. Most implementations for the old interface were put into forms for reason i can neither understand nor change. Because those tend to be displayed and disposed, i have to create a new instance every time i use ObjectFactory.GetAllInstances(Of IFoo). Thats still no problem, but i’d like to register a INewFoo-Wrapper for each registered implementation of IFoo, so that i can just use ObjectFactory.GetAllInstances(of INewFoo) and get all implementations of IFoo AND INewFoo.

I can’t iterate through the implementations of IFoo and register a wrapper for each one because as far as i can see, you can just register those with instances.

Wrong code below:

  ObjectFactory.Configure(Sub(config)
                            config.Scan(Sub(scan)
                                          For Each ass In assemblies
                                            scan.Assembly(ass)
                                          Next
                                          scan.AddAllTypesOf(Of IFoo)()
                                        End Sub)
                          End Sub)

Dim oldImplementations = ObjectFactory.GetAllInstances(Of IFoo)()

  ObjectFactory.Configure(Sub(config)
                            For Each implementation In oldImplementations
                              Dim notIterated = implementation
                              config.For(Of INewFoo).Add(Function(x) New FooToNewFooWrapper(notIterated))
                            Next
                          End Sub)

My question is: Is it possible to register a wrapper for each implementation of IFoo which always creates a new instance of the implementation before creating a new instance of the wrapper?

Answers in C# and Vb.net are equally welcome.

  • 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-27T01:13:45+00:00Added an answer on May 27, 2026 at 1:13 am

    Have you tried implementing a custom registration convention to carry out your specific requirement? Custom registration conventions allow very flexible scanning and registering

    [CLSCompliant(false)]
    public class MyRegistration : IRegistrationConvention
    /// <inheritdoc />
        public void Process(Type type, Registry registry)
        {           
    
            Type interfaceType = type.GetInterface(typeof(IFoo).Name);
            if (interfaceType == null)
            {
                return;
            }
    
            registry.AddType(interfaceType, type, type.Name);
    
            // Do your stuff with INewFoo
    
        }
    }
    

    Configure structure map to use your scanner:

    ObjectFactory.Configure(item =>
                {
                    item.Scan(
                        x =>
                        {
                            x.AssembliesFromPath("c:\wheremyassemblyis.dll");
                            x.With(new MyRegistration());
                        });
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Morning all Now I know there is a reason to this odering but my
Morning all I have frequently used the old <asp:Label ID=lblWas runat=server Text='<%# XPath(FACEVALUE) %>'></asp:Label>
Morning, Regarding the following quote, is this limit independent of how many columns there
Morning all, I've created a custom control with an image property. That image property
Morning stackoverflow, I have a repeater, with the following code in my aspx page;
Morning y'all This is probably an easy one but I barely got any sleep
This morning, I was reading Steve Yegge's: When Polymorphism Fails , when I came
Good morning, I am about to start writing an Excel add-in for Excel 2002.
Every morning, after logging into your machine, you do a variety of routine stuffs.
This morning I ran into an issue with returning back a text string as

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.