Register Multiple implementations of the same contract : one in Chilcontainer and one in the Parent


I am trying to register multiple implementations of the same interface like this :-

**DLL A: Module.cs** _container.RegisterType<IFoo, Foo1>("Foo1"); <hr />**DLL B: Module.cs** var childContainer = _container.CreateChildContainer(); //childcontainer childContainer.RegisterType<IFoo, Foo2>("Foo2"); <hr />**DLL A: Resolve IFoo for Foo2** (But, resolving IFoo for Foo1 is fine) var foo2 = container.Resolve<IFoo>("Foo2"); //Error

<em>Note: The container which I receive here is the "childcontainer". Have checked the hashcode.</em>



A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Practices.Unity.dll

Additional information: The current type, IFoo, is an interface and cannot be constructed. Are you missing a type mapping?

</blockquote> <hr />

<strong>But</strong>, it works, if I do the registration of Foo2 in DLL A just after Foo1 i.e. like this :

_container.RegisterType<IFoo, Foo1>("Foo1"); _container.RegisterType<IFoo, Foo2>("Foo2");

Is Registration (Register) and Resolution (Resolve) dependent upon scope & assembly ? I want the 1st approach to work. Any idea ?


I tried the next example and is working for me. Just be carefull with assembly references and namespace includes.

**Dll A Public Interface Ifoo End Interface <hr />**Dll B Public Class Class1 Public Shared function registerOtherType(container AS IUnityContainer) As IUnityContainer Dim c As IUnityContainer = container.CreateChildContainer c.RegisterType(of Ifoo, foo2)("2") Return c End Function End Class Public Class foo2 Implements Ifoo End Class <hr />**Dll C Public Class foo Implements Ifoo End Class Sub Main() 'init() 'Dim manager As IClasificationManagement = ServiceLocator.Current.GetInstance(Of IClasificationManagement)() 'manager.SwapDescrition("1", "2") 'Console.WriteLine("Operacion Realizada") 'Console.Read() Dim container As IUnityContainer = New UnityContainer() container.RegisterType(Of Ifoo, foo )("1") dim child As IUnityContainer = Class1.registerOtherType(container) child.Resolve(of Ifoo)("2") End Sub


  • How to disable an extra window to restart system even after selecting not to do so in files in use d
  • How to get the scale of a svgElement?
  • How to collect and store tellp(), tellg() return types?
  • top n keys with highest values in dictionary with tuples as keys
  • How do I load custom configuration files with codeigniter?
  • Create and import mysql database on shared host in php
  • SVG Filter tag on hover
  • Multiplying two matrices in Java
  • Visual Studio Professional 2012 svhost32.exe error running hello world
  • Getting the BuildAgent information from a Build
  • Generate Weighted Random Boolean Matrix in Matlab
  • Why my input is showing one thread executing after another thread, not at the same time?
  • Not getting Segmentation Fault in C
  • NetBeans moving tabs navigation to the right
  • Custom URI routing by query string with CodeIgniter?
  • xpages partial - full search
  • How can I manually set the document id in a corpus?
  • jQuery Mobile - Dialogs without changing hash
  • Insert records if not exist SQL Server 2005
  • Google analytics measurement protocol session timeout and query time limits
  • Accessing Rows In A LINQ Result Without A Foreach Loop?
  • Undefined references when compiling gSOAP client
  • why do I get the error when installing the gem 'pg'? [duplicate]
  • Master page gives error
  • Launch Runnable Jar from Web Start
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • javascript inside java/jsp code
  • Validaiting emails with Net.Mail MailAddress
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Google cloud sdk not working when python points python3
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Android Studio and gradle
  • Proper folder structure for lots of source files
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • How does Linux kernel interrupt the application?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Binding checkboxes to object values in AngularJs
  • How can i traverse a binary tree from right to left in java?