Sponsors

News

Jobping Laurent Kempé MVP JetBrains Academy Member Certified ScrumMaster

Contact

My status

View Laurent Kempé's profile on LinkedIn
XING
twitter
facebook


Xbox 360



Map

Locations of visitors to this page

.NET Dudes

Family

French .NET Dudes

Friends

Jobping

Links

Tech Head Brothers

Business entity and C# extension methods

In place of writing something like:

protected string GetUrl(Information info)
{
    if (info is News)
        return ResolveUrl(string.Format("~/news.aspx/{0}", info.NormalizedTitle));
    else if (info is Publication)
        return ResolveUrl(string.Format("~/publications.aspx/{0}", info.NormalizedTitle));
    else
        return string.Empty;
}

I would use on the presentation layer only an extension method on my business entity class of type Information to add a GetUrl method!

It would keep the business entity light on the different other layers, and add web responsibilities on the presentation layer.

And would end like so:

<a href="<%# ((Information)Container.DataItem)).GetUrl() %>" title="<%#Eval("Title")%>">
    <%#Eval("Title")%>
</a>

Something to test when I will install Visual Studio 2008!

Posted: Oct 31 2007, 05:56 PM by lkempe | with 3 comment(s)
Filed under:

Comments

AndrewSeven said:

In a case like that, I would be more likely to create a control InformationHyperlink that would have an Information property and would output the html.

<prefix:InformationHyperlink runat=server id=Info1

Information="<%# (Information)Container.DataItem %>" />

# November 1, 2007 8:57 AM

lkempe said:

Andrew: Yeah why not, maybe my example is not the best one! What I want to emphasis is that with this you can extend business entities functionnalities per layer.

# November 1, 2007 10:17 AM

Laurent Kempé said:

I started yesterday the migration of Tech Head Brothers portal to .NET Framework 3.5 and Visual Studio

# November 28, 2007 7:01 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)