Gustavo Melo | 6 Aug 05:22

Best Way?

Hello EverBody,

I'm a little confuse in how i implement some part of my application.
The picture shows how my app works today.
Look in webapp i don't use "Model" from MVC, bcuz all the model logic stay in DDD.
I'm wondering about how is the best way to do the logic below:
In my blog i want to save one POST.
So my Form in one View call one Action for Controller and send the parameters.

A)
        Controller.cs
        public virtual ActionResult IncludePost()
        {
            Post post = new Post();
            post.Title = Request.Form["Title"];
            post.Text = Request.Form["Text"];
            post.Creation = DateTime.Now;
            BlogService.AddPost(post);
            return View("Message");
        }

        BlogService.cs
        public void AddPost(string title, string text)
        {           
            PostRepository.Add(post);
        }

B)
        Controller.cs
        public virtual ActionResult IncludePost()
        {           
            BlogService.AddPost(Request.Form["Title"], Request.Form["Text"]);
            return View("Message");
        }

        BlogService.cs
        public void AddPost(string title, string text)
        {
            Post post = new Post();
            post.CreatPost(title, text);
            PostRepository.Add(post);
        }

        Post.cs
        public void CreatPost(string title, string text)
        {
            this.title = title;
            this.text = text;
            this.creation = DateTime.Now;
        }

What is the best Way? A? B? Both? Neither?

Best Regards.
__._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___
Luiz Esmiralha | 6 Aug 05:39

Re: Best Way?

B is better to me.

In Design A, Controller is coupled to Post but in Design B it is not.
So B is less coupled to me.

Hope it helps,
Luiz

On Wed, Aug 6, 2008 at 12:26 AM, Gustavo Melo <pipocadr <at> gmail.com> wrote:
> Hello EverBody,
>
> I'm a little confuse in how i implement some part of my application.
> The picture shows how my app works today.
> Look in webapp i don't use "Model" from MVC, bcuz all the model logic stay
> in DDD.
> I'm wondering about how is the best way to do the logic below:
> In my blog i want to save one POST.
> So my Form in one View call one Action for Controller and send the
> parameters.
>
> A)
>         Controller.cs
>         public virtual ActionResult IncludePost()
>         {
>             Post post = new Post();
>             post.Title = Request.Form["Title"];
>             post.Text = Request.Form["Text"];
>             post.Creation = DateTime.Now;
>             BlogService.AddPost(post);
>             return View("Message");
>         }
>
>         BlogService.cs
>         public void AddPost(string title, string text)
>         {
>             PostRepository.Add(post);
>         }
>
> B)
>         Controller.cs
>         public virtual ActionResult IncludePost()
>         {
>             BlogService.AddPost(Request.Form["Title"],
> Request.Form["Text"]);
>             return View("Message");
>         }
>
>         BlogService.cs
>         public void AddPost(string title, string text)
>         {
>             Post post = new Post();
>             post.CreatPost(title, text);
>             PostRepository.Add(post);
>         }
>
>         Post.cs
>         public void CreatPost(string title, string text)
>         {
>             this.title = title;
>             this.text = text;
>             this.creation = DateTime.Now;
>         }
>
> What is the best Way? A? B? Both? Neither?
>
> Best Regards.
> 

------------------------------------

moffdub | 6 Aug 12:53
Favicon

Re: Best Way?

I agree. Simple as it is in this case, Single Responsibility suggests
that B is better because Controller has only one job and delegates the
"mapping" between Request and Post to the service.

--- In domaindrivendesign <at> yahoogroups.com, "Luiz Esmiralha"
<esmiralha@...> wrote:
>
> B is better to me.
> 
> In Design A, Controller is coupled to Post but in Design B it is not.
> So B is less coupled to me.
> 
> Hope it helps,
> Luiz
> 
> 
> On Wed, Aug 6, 2008 at 12:26 AM, Gustavo Melo <pipocadr@...> wrote:
> > Hello EverBody,
> >
> > I'm a little confuse in how i implement some part of my application.
> > The picture shows how my app works today.
> > Look in webapp i don't use "Model" from MVC, bcuz all the model
logic stay
> > in DDD.
> > I'm wondering about how is the best way to do the logic below:
> > In my blog i want to save one POST.
> > So my Form in one View call one Action for Controller and send the
> > parameters.
> >
> > A)
> >         Controller.cs
> >         public virtual ActionResult IncludePost()
> >         {
> >             Post post = new Post();
> >             post.Title = Request.Form["Title"];
> >             post.Text = Request.Form["Text"];
> >             post.Creation = DateTime.Now;
> >             BlogService.AddPost(post);
> >             return View("Message");
> >         }
> >
> >         BlogService.cs
> >         public void AddPost(string title, string text)
> >         {
> >             PostRepository.Add(post);
> >         }
> >
> > B)
> >         Controller.cs
> >         public virtual ActionResult IncludePost()
> >         {
> >             BlogService.AddPost(Request.Form["Title"],
> > Request.Form["Text"]);
> >             return View("Message");
> >         }
> >
> >         BlogService.cs
> >         public void AddPost(string title, string text)
> >         {
> >             Post post = new Post();
> >             post.CreatPost(title, text);
> >             PostRepository.Add(post);
> >         }
> >
> >         Post.cs
> >         public void CreatPost(string title, string text)
> >         {
> >             this.title = title;
> >             this.text = text;
> >             this.creation = DateTime.Now;
> >         }
> >
> > What is the best Way? A? B? Both? Neither?
> >
> > Best Regards.
> >
>

------------------------------------

Eben Roux | 6 Aug 12:57

Re: Best Way?

Hello,

If SRP is a problem create a mapper between NameValueCollection and 
Entity.  Then inject into the controller.

Just a though.

Eben

------------------------------------


Gmane