2

I am using Microsoft extension dependency injection in Sitecore 8.2 update 4 with Helix Framework, below is my code:

public class TestTextHandler : IHttpHandler
{
    private readonly ITest _test;

    public TestTextHandler(Test test)
    {
        _test = test;
    }
}

public interface ITest
{
}

public class Test : ITest
{
}

public class RegisterContainer : IServicesConfigurator
{
    public void Configure(IServiceCollection serviceCollection)
    {
        serviceCollection.AddTransient<ITest, Test>();
    }
}

One patch file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <services>
      <configurator type="XX.XX.RegisterContainer, XX.XX" />
    </services>
  </sitecore>
</configuration>

I am getting error Constructor on type 'XX.XX.TestTextHandler' not found.

Christian Hagelid
  • 8,275
  • 4
  • 40
  • 63
Swati Gupta
  • 753
  • 2
  • 8
  • 30

2 Answers2

1

You are getting the error because you have configured your TestTextHandler to take a concrete Test object instead of an object that inherits your ITest interface.

You need to change your constructor declaration to: public TestTextHandler(ITest test)

Christian Hagelid
  • 8,275
  • 4
  • 40
  • 63
0

I just tried your code above (plus the interface implementation of IHttpHandler) and it worked just fine using the Habitat solution. Check to make sure that the assembly is being published in the /bin folder and the config is correct. (FY: I even checked the ShowServicesConfig.aspx to make sure it's getting loaded and it does with a Lifetime of transient.)

Marco
  • 111
  • 3