Copied to clipboard

Flag this post as spam?

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


  • Simon 692 posts 1067 karma points
    Sep 02, 2016 @ 14:17
    Simon
    0

    Depedancy Injection in classes implementing ApplicationEventHandler - Umbraco 7.4

    Hi Guys,

    I have project which has Dependency injection controlled by SimpleInjector.

    Now, I have a class which is implementing from ApplicationEventHandler where I want to listen to such member service event. In such events, I want to call such services which do some logic, as below:

    public class MemberServiceEventsHandler : ApplicationEventHandler
        {
    
            private readonly ISetMemberThatApprovalHasBeenDoneAtLeastOnceService _setMemberThatApprovalHasBeenDoneAtLeastOnceService;
    
            public MemberServiceEventsHandler(ISetMemberThatApprovalHasBeenDoneAtLeastOnceService setMemberThatApprovalHasBeenDoneAtLeastOnceService)
            {
                _setMemberThatApprovalHasBeenDoneAtLeastOnceService = setMemberThatApprovalHasBeenDoneAtLeastOnceService;
            }
    
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                MemberService.Saving += MemberService_Saving;
                MemberService.Saved += MemberService_Saved;
            }
    
            private void MemberService_Saving(IMemberService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IMember> e)
            {
                foreach (var node in e.SavedEntities)
                {
                    if (node.ContentType.Alias == ConstantValues.DefaultMemberTypeAlias)
                    {
                        _memberApprovalStatusHasBeenChanged = node.IsPropertyDirty(ConstantValues.MemberIsApprovedAliasName);
                    }
                }
            }
    }
    

    But when I start the application and debugged accordingly, events are not being registered and eventaully it is not working.

    I don't want to use such static call for service and use it like that unless there are no solution.

    Appreciate any help.

    Thank you.

    Kind Regards

  • Simon 692 posts 1067 karma points
    Sep 03, 2016 @ 07:47
    Simon
    0

    Anyone can help me please?

    Kind Regards

  • Dale McCutcheon 22 posts 124 karma points
    Feb 21, 2019 @ 14:34
    Dale McCutcheon
    0

    Hey Simon,

    Did you ever managed to get this working? I am having the same issue

    Thanks Dale

  • Dale McCutcheon 22 posts 124 karma points
    Jun 14, 2019 @ 13:05
    Dale McCutcheon
    0

    Hey Simon,

    Just on this, i never managed to get it working and instead have to retrieve the Interface from the service locator instead.

    Cheers Dale

Please Sign in or register to post replies

Write your reply to:

Draft