1

Problem: user operates over some entity in a domain. The last one changes its status so that user recieves e-mail notifications (using smtp server) repeatedly until the given time.
So I need to fire an event somehow.

What are the alternative ways to do that? I know there're no events in ASP.NET MVC framework.

Thanks!

2
  • I know there're no events in ASP.NET MVC - Say what? Commented Aug 27, 2012 at 8:53
  • I don't understand your comment? Commented Aug 27, 2012 at 8:58

1 Answer 1

1

You can use my Inversion Of Control container which has built in support for in-process domain events:

Subscribing

Subscribing is easy. Simply let any class implement IHandlerOf:

[Component]
public class ReplyEmailNotification : IHandlerOf<ReplyPosted>
{
    ISmtpClient _client;
    IUserQueries _userQueries;

    public ReplyEmailNotification(ISmtpClient client, IUserQueries userQueries)
    {
        _client = client;
        _userQueries = userQueries;
    }

    public void Invoke(ReplyPosted e)
    {
        var user = _userQueries.Get(e.PosterId);
        _client.Send(new MailMessage(user.Email, "bla bla"));
    }
} 

Dispatching

Domain events are dispatched using the DomainEvent class. The actual domain event can be any class, there are no restrictions. I do however recommend that you treat them as DTO's.

public class UserCreated
{
    public UserCreated(string id, string displayName)
    {
    }
}

public class UserService
{
    public void Create(string displayName)
    {
        //create user
        // [...]

        // fire the event.
        DomainEvent.Publish(new UserCreated(user.Id, user.DisplayName));
    }
}

The code is from my article: http://www.codeproject.com/Articles/440665/Having-fun-with-Griffin-Container

ASP.NET MVC3 installation:

  1. Use package manager console: install-package griffin.container.mvc3
  2. Follow these instructions: http://griffinframework.net/docs/container/mvc3/
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.