Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 13, 2019 @ 22:24
    Ismail Mayat
    0

    Make sure that the controller has a parameterless public constructor

    I am in the process of upgrading the package https://our.umbraco.com/packages/backoffice-extensions/redirects-viewer/ to v8.

    When creating a property editor I am getting an error with one of the controllers the error is:

    An error occurred when trying to create a controller of type 'UserGroupsApiController'. Make sure that the controller has a parameterless public constructor

    The controller inherits from BackOfficeNotificationsController this does not have parameterless constructor only inherited one that must have dependencies injected into it.

    The inner states:

    System.InvalidOperationException: Unresolved dependency [Target Type: Our.Umbraco.RedirectsViewer.Controllers.UserGroupsApiController], [Parameter: mapper(AutoMapper.IMappingEngine)], [Requested dependency: ServiceType:AutoMapper.IMappingEngine, ServiceName:]

    In my composer I have:

            composition.Register<IMappingEngine,MappingEngine>(Lifetime.Singleton);
    

    So I am setting it up, am I missing something?

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 14, 2019 @ 12:15
    Ismail Mayat
    100

    So got a bit further with this, I updated automapper to latest version then in my composition I now have:

    var config = new MapperConfiguration(cfg => {
                cfg.AddProfile<UserGroupProfile>();
            });
    
            IMapper mapper = new Mapper(config);
    
            composition.Register(mapper);
    

    Is there better way to register this? Also I want to register as singleton lifetime how would i do this?

    Regards

    Ismail

  • Alan Draper 57 posts 140 karma points
    Dec 11, 2019 @ 17:10
    Alan Draper
    0

    Did you get an answer to this? I'm getting the same message injecting into a custom controller.

  • Alan Draper 57 posts 140 karma points
    Dec 11, 2019 @ 20:26
    Alan Draper
    1

    I think I may have found the answer on the LightInject site; you need to register your controller assembly. This did it for me:

    public class ControllerStartupComposer : IUserComposer {
        public void Compose(Composition composition) {
            var serviceContainer = composition.Concrete as LightInject.ServiceContainer;
            serviceContainer.RegisterApiControllers(GetType().Assembly);            
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft