Let's consider a quite simple domain: Article, Feedback, Category. For example when
user tries to attach a feedback to a closed article or when feedbacks quota is exceeded user should be notified. So what I want to implement is
messaging between domain layer and presentation/application layer. I found several articles on
domain events, but I'm afraid it is gonna add extra complexity to domain layer. But I consider it though.
What the best (also best illustrated) way to implement such a thing.
You are totally right about it! But let me extend the context: user should be notified how many feedbacks it possible to attach. Then there is variety of cases when user should be notified. Quite not all activities I wanna provide/treat as exceptions or
validation broken rule. I hope you understand what I mean
On my current project I use an event based system. There is a controller that handles events (no .NET events but the concept and not the controller from MVC also). The return from an "event handler" is an OutputAction (in fact extensions of the OutputAction
abstract class).
So you can have an an event called AttachFeedbackEvent and the output action can be:
FeedbackAttached with a property remaning feedbacks in case of success or
FedbackAttachingFailed in case the user cannot attach more feedbacks.
Can't understand what does it mean 'Registry'? Is it kinda facade/singleton? Also didn't understand whether M. Fowler uses internal fields for brevity?
In the Registry you register your event handlers. My implementation is a basic version of the one in the article. The Registry is named EventPipeline and is not a singleton. I depends on your requirements if you want to make is singleton or not.
helicera
Also didn't understand whether M. Fowler uses internal fields for brevity?
My thoughts exactly when I've read that article. I've never seen so many "internal"s in my entire developer life :)
Please click 'Mark as Answer' if my reply has assisted you
In his article he uses a Unity container. But I instead use (in quite straightforward manner: installed from nugget
then assigned services) Ninject container. I have placed
DomainEvents class inside domain layer assembly and now I don't know how do I use
Ninject container?
I mean that I need to refactor the class to register all IHandle<[Event]> in Global.asax.
helicera
Member
20 Points
28 Posts
Implementing Domain Layer/Application Layer messaging alternatives
May 04, 2012 12:32 PM|LINK
Hello!
Let's consider a quite simple domain: Article, Feedback, Category. For example when user tries to attach a feedback to a closed article or when feedbacks quota is exceeded user should be notified. So what I want to implement is messaging between domain layer and presentation/application layer. I found several articles on domain events, but I'm afraid it is gonna add extra complexity to domain layer. But I consider it though.
What the best (also best illustrated) way to implement such a thing.
raduenuca
All-Star
24675 Points
4250 Posts
Re: Implementing Domain Layer/Application Layer messaging alternatives
May 04, 2012 12:39 PM|LINK
This sound like a validation to me:
http://blog.goneopen.com/2011/02/aspnet-mvc-putting-our-model-layer-in-charge-of-validation/
Radu Enuca | Blog
helicera
Member
20 Points
28 Posts
Re: Implementing Domain Layer/Application Layer messaging alternatives
May 04, 2012 01:03 PM|LINK
You are totally right about it! But let me extend the context: user should be notified how many feedbacks it possible to attach. Then there is variety of cases when user should be notified. Quite not all activities I wanna provide/treat as exceptions or validation broken rule. I hope you understand what I mean
I've found article http://blogs.taiga.nl/martijn/2011/05/03/keep-your-users-informed-with-asp-net-mvc/ but can't get does it fit my requirements/environment?
Of course I can use extra controller logic to extract results to show up to user with help of ViewBag.
But I'm interested in stable practics, alternatives, it's a pity that books on ASP.NET MVC don't cover the issue
Do you have any ideas? Whether the approach with controllers is sufficient enough?
raduenuca
All-Star
24675 Points
4250 Posts
Re: Implementing Domain Layer/Application Layer messaging alternatives
May 04, 2012 03:46 PM|LINK
On my current project I use an event based system. There is a controller that handles events (no .NET events but the concept and not the controller from MVC also). The return from an "event handler" is an OutputAction (in fact extensions of the OutputAction abstract class).
So you can have an an event called AttachFeedbackEvent and the output action can be:
FeedbackAttached with a property remaning feedbacks in case of success or
FedbackAttachingFailed in case the user cannot attach more feedbacks.
You can have a look here:
http://martinfowler.com/eaaDev/EventSourcing.html
Radu Enuca | Blog
helicera
Member
20 Points
28 Posts
Re: Implementing Domain Layer/Application Layer messaging alternatives
May 07, 2012 06:10 AM|LINK
Thanks! It is great!
helicera
Member
20 Points
28 Posts
Re: Implementing Domain Layer/Application Layer messaging alternatives
May 07, 2012 12:37 PM|LINK
Can't understand what does it mean 'Registry'? Is it kinda facade/singleton? Also didn't understand whether M. Fowler uses internal fields for brevity?
raduenuca
All-Star
24675 Points
4250 Posts
Re: Implementing Domain Layer/Application Layer messaging alternatives
May 07, 2012 01:32 PM|LINK
In the Registry you register your event handlers. My implementation is a basic version of the one in the article. The Registry is named EventPipeline and is not a singleton. I depends on your requirements if you want to make is singleton or not.
My thoughts exactly when I've read that article. I've never seen so many "internal"s in my entire developer life :)
Radu Enuca | Blog
helicera
Member
20 Points
28 Posts
Re: Implementing Domain Layer/Application Layer messaging alternatives
Aug 29, 2012 12:00 PM|LINK
Hello, again!
I have followed the example from Udi Dahan (http://www.udidahan.com/2009/06/14/domain-events-salvation/). That's really cool. But I have trouble figuring out how do I wire up service location for ninject?
In his article he uses a Unity container. But I instead use (in quite straightforward manner: installed from nugget then assigned services) Ninject container. I have placed DomainEvents class inside domain layer assembly and now I don't know how do I use Ninject container?
I mean that I need to refactor the class to register all IHandle<[Event]> in Global.asax.
Have any ideas?
Thanks!