Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Moze 3 posts 73 karma points
    1 week ago
    Moze
    0

    Dependency injection is broken?

    Hi, i am trying to use built in dependency injection system, but no luck. Here is the code and an error

    public class DependencyInjectionComponent : IUserComposer
        {
            public void Compose(Composition composition)
            {
                composition.RegisterFor<IA, A>(Lifetime.Singleton);
            }
        }
        public interface IA
        {
        }
        public class A : IA
        {
            public A()
            {
            }
        }
    

    Next is the code of controller

       [RoutePrefix("api/Search")]
        public class SearchController : UmbracoApiController
        {
            public SearchController(IA a)
            {
            }
    
        [HttpGet, Route("Test")]
        public object Test()
        {
        }
    }
    

    So when i trigger localhost:666/api/Search/Test, i get an error:

    This XML file does not appear to have any style information associated with it. The document tree is shown below.

    As you can see, an inner exception says that "Missing public constructor for Type: DoctorAsYou.Custom.Umbraco_.Components.IA". But c'mon, there actually is an empty public constructor.

    Any chance to fix this ?

Please Sign in or register to post replies

Write your reply to:

Draft