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.