Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving 2 Objects of same type but different version #22

Open
Ghislain1 opened this issue Jun 15, 2019 · 0 comments
Open

Resolving 2 Objects of same type but different version #22

Ghislain1 opened this issue Jun 15, 2019 · 0 comments
Labels
Question ❔ Issue is a question

Comments

@Ghislain1
Copy link

Description

We have a scenario where we can registry in config file 2 Singleton of the same type but different dll version. In the background we have 2dll classes (Only different version) which all implement the desired interface. We would like to use Unity to resolve 2 instances for this interface.

To Reproduce

  1. Create config file
  <unity>
    <aliases>
      <add alias="DtmParameter1" type="FullFrameworkLibLogic.DtmParameter,  FullFrameworkLibLogic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <add alias="DtmParameter2" type="FullFrameworkLibLogic.DtmParameter, FullFrameworkLibLogic, Version=5.5.5.5, Culture=neutral, PublicKeyToken=null" />
      <add alias="my" type="FullFrameworkLibLogic.DtmParameter, FullFrameworkLibLogic" />

      
    </aliases>
    <container>

      <register name="1" type="IDtmParameter" mapTo="DtmParameter1">
<lifetime type="singleton" />
      </register>

      <register name="2" type="IDtmParameter" mapTo="DtmParameter2">
        <lifetime type="singleton" />
      </register>
    </container>
  </unity>
</configuration>
  1. Test like this

[TestMethod]
public void SomeDescriptiveName()
{
        IDtmParameter dtmParameter1 = this.container.Resolve<IDtmParameter>("1");
            var msg1 = dtmParameter1.GetVersion();
            Console.WriteLine(msg1);

            IDtmParameter dtmParameter2 = this.container.Resolve<IDtmParameter>("2");
            var msg2 = dtmParameter2.GetVersion();
            Console.WriteLine(msg2);
}

image

@Ghislain1 Ghislain1 changed the title Resolving 2 Object from same type but different version Resolving 2 Objects of same type but different version Jun 15, 2019
@ENikS ENikS transferred this issue from unitycontainer/container Jun 15, 2019
@ENikS ENikS added this to the Bugs and Questions milestone Apr 3, 2020
@ENikS ENikS added the Question ❔ Issue is a question label Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question ❔ Issue is a question
Projects
None yet
Development

No branches or pull requests

2 participants