container icon indicating copy to clipboard operation
container copied to clipboard

UnityContainer defaults for internal constructor with more params over a public default one

Open hawayel opened this issue 6 years ago • 3 comments

Container defaults to internal constructor with more parameters over a public default constructor, Expected behavior is that the public empty constructor should be used; i.e. internal constructor should be treated as private? The following test fails.

[Test]
public void TestCtrSelection()
{
var uc = new UnityContainer();
uc.RegisterType<Service>();
uc.Resolve<Service>();
}
class CoreLogic
{
}
class Service
{   
 public CoreLogic Logic { get; private set; }
 internal Service(CoreLogic cl)
 {  
   Logic = cl;
   Assert.Fail("Defaulted to internal ctr");
 }
 public Service()
 {
   Logic = new CoreLogic();
   Assert.Pass();
 }
}

hawayel avatar Jun 23 '20 17:06 hawayel

In Unity v6 it will be possible to change set of members (public, private, internal) included in selection.

ENikS avatar Sep 29 '20 19:09 ENikS

@ENikS is there any workaround for version 5 which can be used for a third-party library that uses IServiceCollection only and a service to be resolved is an internal class?

xakep139 avatar Apr 14 '23 15:04 xakep139

not really

ENikS avatar Apr 14 '23 19:04 ENikS