Re: [sharp-architecture] SharpArch.Domain.Commands.CommandHandlerNotFoundException was unhandled by user code.

111 views
Skip to first unread message

Seif Attar

unread,
Mar 25, 2013, 8:03:16 PM3/25/13
to sharp-arc...@googlegroups.com
Hello,

Is your command handler in infrastructure or in tasks? I dont think you need the AddCommandsTo method why woud you need to register everything in Infra?

When you look at the registered handler in all components/services in the container is it registered with a "/ICommandHandler<ChangeActivityCommand>"?

Looking at your code it should work, I can't see what could be wrong.

If it is a test solution, you can upload it somewhere and I'll have a look.




On 25 March 2013 15:45, Dheeraj <dheeraj...@gmail.com> wrote:
Hi Ya,

Please would anyone help in pointing out the right direction to fix the following issue, I used the older version of Sharp Architecture (1.9.6) but we are planning to use new SA for one of our new projects. I am just playing around some sample applications to understand, I might be missing something very obvious:

Please note that I have used cookbook as a template.

Error:

SharpArch.Domain.Commands.CommandHandlerNotFoundException was unhandled by user code
  HResult=-2146233088
  Message=Command handler not found for command type: ProcimDev.Infrastructure.Commands.ChangeActivityCommand
  Source=SharpArch.Domain
  StackTrace:
       at SharpArch.Domain.Commands.CommandProcessor.Process[TCommand](TCommand command) in d:\Builds\SharpArch2\Solutions\SharpArch.Domain\Commands\CommandProcessor.cs:line 20
       at ProcimDev.Controllers.Activities.ActivityController.UpdateStartAndEndTime(ActivityFormViewModel activityformViewModel) in ..\Solutions\ProcimDev.Controllers\Activities\ActivityController.cs:line 51
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClassf.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
       at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
  InnerException:


Debug Information:

I could see the ChangeActivityCommandHandler in the following:

a) All Components
b) All Services

ChangeActivityCommand is found in:

c) Potentially misconfigured Components.


Below is the source code :

Command

 public class ChangeActivityCommand : CommandBase
    {
        public ChangeActivityCommand(int id, DateTime scheduledStart, DateTime scheduledEnd)
        {
            this.Id = id;
            this.ScheduledStart = scheduledStart;
            this.ScheduledEnd = scheduledEnd;
        }

        [Required]
        public int Id { get; set; }

        public DateTime ScheduledStart { get; set; }
        public DateTime ScheduledEnd { get; set; }
    }

Command Handler:

    public class ChangeActivityCommandHandler : ICommandHandler<ChangeActivityCommand>
    {
        private readonly INHibernateRepository<Activity> activityRepository;

        public ChangeActivityCommandHandler(INHibernateRepository<Activity> activityRepository)
        {
            this.activityRepository = activityRepository;
        }

        public void Handle(ChangeActivityCommand command)
        {
            var activity = this.activityRepository.Get(command.Id);
            activity.ScheduledStart = command.ScheduledStart;
            activity.ScheduledEnd = command.ScheduledEnd;
            this.activityRepository.SaveOrUpdate(activity);
        }
    }


Component Registrar:

    public class ComponentRegistrar
    {
        public static void AddComponentsTo(IWindsorContainer container)
        {
            AddGenericRepositoriesTo(container);
            AddCustomRepositoriesTo(container);
            AddQueryObjectsTo(container);
            AddTasksTo(container);
            AddCommandsTo(container);
        AddHandlersTo(container);
        //AddCommandHandlersTo(container);
        }

        private static void AddTasksTo(IWindsorContainer container)
        {
            container.Register(
                AllTypes
                    .FromAssemblyNamed("ProcimDev.Tasks")
                    .Pick()
                    .WithService.FirstNonGenericCoreInterface("ProcimDev.Domain"));
        }

        private static void AddCustomRepositoriesTo(IWindsorContainer container)
        {
            container.Register(
                AllTypes
                    .FromAssemblyNamed("ProcimDev.Infrastructure")
                    .Pick()
                    .WithService.FirstNonGenericCoreInterface("ProcimDev.Domain"));
        }

        private static void AddGenericRepositoriesTo(IWindsorContainer container)
        {

            container.Register(
                Component.For(typeof(IEntityDuplicateChecker))
                    .ImplementedBy(typeof(EntityDuplicateChecker))
                    .Named("entityDuplicateChecker"));

            container.Register(
                Component.For(typeof(INHibernateRepository<>))
                    .ImplementedBy(typeof(NHibernateRepository<>))
                    .Named("nhibernateRepositoryType")
                    .Forward(typeof(IRepository<>)));

            container.Register(
                Component.For(typeof(INHibernateRepositoryWithTypedId<,>))
                    .ImplementedBy(typeof(NHibernateRepositoryWithTypedId<,>))
                    .Named("nhibernateRepositoryWithTypedId")
                    .Forward(typeof(IRepositoryWithTypedId<,>)));

            container.Register(
        Component.For(typeof(ILinqRepository<>))
            .ImplementedBy(typeof(LinqRepository<>))
            .Named("linqrepository")
                );

            container.Register(
        Component.For(typeof(ILinqRepositoryWithTypedId<,>))
            .ImplementedBy(typeof(LinqRepositoryWithTypedId<,>))
            .Named("linqRepositoryWithTypeId")
                );

            container.Register(
                    Component.For(typeof(ISessionFactoryKeyProvider))
                        .ImplementedBy(typeof(DefaultSessionFactoryKeyProvider))
                        .Named("sessionFactoryKeyProvider"));

            container.Register(
                    Component.For(typeof(SharpArch.Domain.Commands.ICommandProcessor))
                        .ImplementedBy(typeof(SharpArch.Domain.Commands.CommandProcessor))
                        .Named("commandProcessor"));
        }

        private static void AddQueryObjectsTo(IWindsorContainer container)
        {
            container.Register(
                AllTypes.FromAssemblyNamed("ProcimDev.Controllers")
                    .Pick()
                    .WithService.FirstInterface());
        }

        private static void AddCommandsTo(IWindsorContainer container)
        {
          container.Register(
                AllTypes.FromAssemblyNamed("ProcimDev.Infrastructure")
                    .Pick()
                    .WithService.FirstInterface());
        }


        private static void AddHandlersTo(IWindsorContainer container) {
            container.Register(
                AllTypes.FromAssemblyNamed("ProcimDev.Tasks")
                    .BasedOn(typeof(ICommandHandler<>))
            .WithService.FirstInterface());


            container.Register(
                AllTypes.FromAssemblyNamed("ProcimDev.Tasks")
                    .BasedOn(typeof(ICommandHandler<,>))
                    .WithService.FirstInterface());

            container.Register(
                            AllTypes.FromAssemblyNamed("ProcimDev.Tasks")
                .BasedOn(typeof(IHandles<>))
                        .WithService.FirstInterface());
        }
        /*private static void AddCommandHandlersTo(IWindsorContainer container) {
            container.Register(
                AllTypes.FromAssemblyNamed("ProcimDev.Tasks")
                    .BasedOn(typeof(ICommandHandler<>))
                    .WithService.FirstInterface());
        }*/
    }



Thank You,
Dheeraj



--
You received this message because you are subscribed to the Google Groups "S#arp Architecture" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharp-architect...@googlegroups.com.
To post to this group, send email to sharp-arc...@googlegroups.com.
Visit this group at http://groups.google.com/group/sharp-architecture?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dheeraj Vanteru

unread,
Mar 26, 2013, 7:19:47 AM3/26/13
to sharp-arc...@googlegroups.com
Hi Seif,

Thank you for the suggestion. I have managed to fix the issue.

I have some questions related to the best practices with Sharp Architecure. Please would you help me point in a right direction.

The commands which updates data, in this case as I understand it makes a call to the database to get the entity back, assign modified data and then call SaveOrUpdate from repository. After this, to commit the changes we are using DBContext. Would it be the same scenario for handling data store with heavy transactions? We are looking at 3000 - 4000 transactions per minute as per the analysis we have done on the current system. We are using WebAPI for our server side if it is any helpful.

A brief background: Current system is a legacy system which was developed and maintained since 1999. We are planning to start upgrade shortly. Hence, we are trying different approaches to identify the best practices. As I am one of the developers using sharp arch from it's early release, I am keen to develop a prototype which can handle those number of transactions. Due to time constraints I didn't have a chance to look at the source code at it's entirety.

Any suggestions would be helpful.

Best Regards,
Dheeraj


Reply all
Reply to author
Forward
0 new messages