smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
582 stars 178 forks source link

Using MvcMailer with a service layer? #7

Closed chobo2 closed 13 years ago

chobo2 commented 13 years ago

Hi

I am very interested in using your library as I think it is cool that I could use views to make good looking emails.

I however don't know how to use it with a service layer. I currently have 2 projects one with my mvc 3 code and one for my repos and service layers.

Right now I need to do this. Controller extracts ViewModel data and passes it to service layer. Service layer does some business logic and depending on what options where chosen sends a email.

I want to send the email but use MvcMailer. However that probably would mean I need to add a reference to MVC in my service layer project. I do not want to do this as I think the service layer and repos should know nothing about MVC. I do this with my VM and use automapper and map them to a domain object and send it to the service layers as I don't want to have selectLists or MVC depended code coming along.

How could I use MvcMailer and still respect the boundaries of the service layer?

Thanks

smsohan commented 13 years ago

Interesting point. I will see if I can help you about this. First thing comes to my mind is, you can push your Mailer classes in the service layer while putting the views in mvc project. But the service layer will need to reference MVC for this to work. I think it's not too bad to add a reference to MVC - if you want to use it's features, such as, view templates. But I will try to figure out if there's a better way! Thanks for writing.


Sent from my iPhone

On 2011-03-27, at 5:24 PM, chobo2 reply@reply.github.com wrote:

Hi

I am very interested in using your library as I think it is cool that I could use views to make good looking emails.

I however don't know how to use it with a service layer. I currently have 2 projects one with my mvc 3 code and one for my repos and service layers.

Right now I need to do this. Controller extracts ViewModel data and passes it to service layer. Service layer does some business logic and depending on what options where chosen sends a email.

I want to send the email but use MvcMailer. However that probably would mean I need to add a reference to MVC in my service layer project. I do not want to do this as I think the service layer and repos should know nothing about MVC. I do this with my VM and use automapper and map them to a domain object and send it to the service layers as I don't want to have selectLists or MVC depended code coming along.

How could I use MvcMailer and still respect the boundaries of the service layer?

Thanks

Reply to this email directly or view it on GitHub: https://github.com/smsohan/MvcMailer/issues/7

justSteve commented 12 years ago

I'm migrating to MVCMailer with a mail-intensive project - would love to see if anything has come from this exploration. thx!

smsohan commented 12 years ago

I wish I could fix this the way I wanted to. But looks like the best bet is, you put the view related code in your MVC layer, possibly extracting out all your business logic in the business layer as you would do for your controllers. The view lookup and web.config modifications are too tightly coupled with the MVC implementation and its simply not possible to extract out the code into a separate business layer as of now.

And if you need to hit it on a scheduled task, expose a WCF endpoint for your mailer and you'll be be able to hit it from a background process. This way, you will have access to httpContext and all the http classes that you need for MVC to work.

Sohan http://smsohan.com skype:smsohan | gtalk:sohan39 | cell: 403-714-2673

On Tue, Nov 15, 2011 at 12:00 PM, justSteve < reply@reply.github.com

wrote:

I'm migrating to MVCMailer with a mail-intensive project - would love to see if anything has come from this exploration. thx!


Reply to this email directly or view it on GitHub: https://github.com/smsohan/MvcMailer/issues/7#issuecomment-2749304

tafs7 commented 11 years ago

Could you do something like use the RazorEngine project (on github also), to udpate the way MvcMailer does templating?

smsohan commented 11 years ago

I was thinking about it. It would make mailing independent of ASP.Net MVC and can be used in a console app or from a class library. Let me know if you'd want to take a lead on this.

Sohan http://smsohan.com skype:smsohan | gtalk:sohan39 | cell: 403-714-2673

On Tue, Jan 15, 2013 at 3:02 PM, tafs7 notifications@github.com wrote:

Could you do something like use the RazorEngine project (on github also), to udpate the way MvcMailer does templating?

— Reply to this email directly or view it on GitHubhttps://github.com/smsohan/MvcMailer/issues/7#issuecomment-12291921.