SharpCrafters Blog

The official blog of SharpCrafters and PostSharp: annoucements, tips & tricks

Webinars
22 February 2012


Join us on Thursday, February 23 at 9:00 AM PST | 12:00 PM EST | 5:00 PM GMT for the next PostSharp Live Webinar when our guest will be Ward Bell.

Ward is V. P. of Technology at IdeaBlade and, with over 25 years of application development experience, he champions the company's customer-focused product direction.

Due to the popular demand of last week's live webinar, we've asked Ward to join us again to show how IdeaBlade's DevForce product uses PostSharp to infuse “Code First” entity model classes - entities like Customer and Order – with rich behaviors that go way beyond property change notification.

During the webinar you will learn:

  • How IdeaBlade uses PostSharp to achieve important product goals
  • Which alternatives to PostSharp the company considered, and rejected
  • What initially worried IdeaBlade about using AOP and PostSharp
  • Where IdeaBlade is planning to go next with PostSharp

If you've ever wondered what difference AOP and PostSharp can make in real products, and want to gain insight into how it can help with your own project, be sure to watch Thursday's webinar.

Happy PostSharping!

-Britt

Community
21 December 2011


If learning more about Aspect Oriented Programming is on your to-do list for 2012, we have some very good news for you.

We’ve teamed up with the good folks at Pluralsight to make it easier than ever for developers to get up to speed on developing with aspects. PostSharp users can sign-up to receive a free 30-day trial membership good towards one Pluralsight online course.

Start learning about Aspect Oriented Programming for .NET today >>

Pluralsight, “the leader in high-quality online training for hardcore developers,” has a huge library of online courses to choose from but, naturally, the course we recommend is Aspect Oriented Programming for .NET by PostSharp MVP and Pluralsight Author, Donald Belcham.

Donald is a senior software developer, independent contractor, author, and trainer based in Edmonton, Canada. He spoke about the topic of Aspect Oriented Programming at NDC and DevTeach Montreal earlier this year, and published the online course on Pluralsight in June.

The course is divided into four parts:

  • Introduction to AOP
  • AOP using Interceptors
  • AOP using IL Code Weaving
  • AOP beyond decorators

From Donald: “My course is perfect for developers who want to learn how to avoid code repetition by implementing AOP in .NET projects using IL Code Weaving frameworks like PostSharp, Interception frameworks like Castle Windsor, and even how to implement AOP without following the traditional decorator pattern.”

Apply for your free 30-day Pluralsight trial membership today and, upon approval, we’ll email you a unique login code plus a link to a special sign-in page for PostSharp users.

Start your free 30-day trial membership today >>

-Britt

Annoucements
2 December 2011


Scott Hanselman knows tools.

As a Principle Program Manager at Microsoft, and one of the most sought-after developer speakers on the planet, Scott has his finger planted firmly on the pulse of the .NET community. Luckily for all of us, he only uses his powers for good by entertaining and educating the community about software development across a variety of channels including podcasts, presentation and speaking tips, books, and more.

Since his first ultimate tools list in 2003, the popularity and length of Scott’s annual lists have grown considerably. This year’s list includes categories such as “The Big Ten Life and Work-Changing Utilities,” “Rocking Sweet Windows 7 Specific Stuff,” and “A (.NET) Developer's Life,” to name a few.

We’re thrilled and honored to see PostSharp included in Scott’s 2011 ultimate tools list alongside so many other great tools. We know we wouldn’t have made the list without the help of our customers, MVPs, and partners. Thank you, all.

The ultimate tools list wasn’t our first run-in with Scott in 2011. Gael sat down with him in September as part of his startup podcast series, to discuss the challenges of taking PostSharp from open source to commercial business. The two talked about aspect-oriented programming and Scott rightly pointed out that AOP is another kind of abstraction, which is the whole point of what computers are supposed to do for us, work that’s not fun like logging and transactions.

Since the beginning of 2011 we’ve focused on spreading the word about the benefits of aspect oriented programming for .NET with in-office trainings, user group and conference presentations, podcasts and screencasts, white paper and blog posts.

It seems to be working.

In September, the same month as the Hanselminutes podcast, we announced a rising trend in AOP adoption among developers in large organizations, especially those in the Fortune 500, and created case studies showing how two big companies, Siemens Audiology and Thales Information Systems, are succeeding with PostSharp.

There’s more to come in 2012, and we look forward to speaking with more of you about your experience with PostSharp. Special thanks goes out to Scott Hanselman for his seemingly tireless commitment to the community and his never-ending quest to find the ultimate tools for .NET.

Happy PostSharping!

-Britt

Annoucement
29 September 2011


We’re thrilled to finally announce the availability of PostSharp training, worldwide. We’ve assembled an experienced team of trainers and consultants to offer a comprehensive 2 day course that’s designed to bring you up to speed fast on aspect-oriented programming and PostSharp.

The course includes hands-on labs and discussion where you’ll learn how to:

  • create PostSharp aspects; and
  • successfully introduce PostSharp aspects into complex projects.

Upon completion, you’ll be able to apply what you’ve learned to your own applications, and produce cleaner, more efficient, higher quality code than ever before.

Meet our Training & Consulting Partners

Donald Belcham is a senior software developer, independent contractor, and agile development expert who is a strong supporter of fundamental OO patterns and practices. He is co-author of the book, Brownfield Application Development in .NET (Manning Press, 2008), and actively shares his expertise with other technical professionals at user groups, code camps and conferences held throughout the world. Past lectures have covered topics that encompass development practices, quality team leadership, and the intricacies of new and emerging technologies.

 

Golo Roden works as self-employed trainer and consultant for C#, JavaScript and web development – focusing on code quality and agile methods. In 2011 he launched the Agile Development Framework, a comprehensive approach which combines the successful elements of previous agile methods. He has written more than 100 articles for professional magazines, has given more than 50 talks at international conferences, and wrote a book on C# in 2008. Golo blogs regularly and writes a recurring column on C# specialties for dotnetpro magazine.

 

Endjin is a collaboration of like-minded people who are imbued with an infectious enthusiasm for solving business problems through the smart application of technology. Their endjin-eers are outstanding individuals who have come together from across the business, creative and technology community having demonstrated a mastery of their craft. Unconstrained by industry vertical, company size or budget; endjin is motivated by solving problems. Their goal is to energize your business whether it is through a 2 hour conversation or 2 years of team effort.

PostSharp Training Agenda

The standard public agenda is composed of the following modules (note: for private training other topics can be introduced after discussion with the trainer):

  • Introduction to AOP
  • Basic aspects
  • Applying aspects to code
  • Interception aspects
  • Aspect composition
  • Composite aspects
  • Deployment and build process integration
  • Targeting different platforms
  • Best practices

We’ve got more exciting training news coming in the weeks ahead and, if you sign-up now to request more information about PostSharp training, we’ll let you in on the exciting news (including an exclusive offer) before we announce it publicly.

Happy PostSharping!

-Britt

Annoucement
15 April 2011


Join us on April 28th as Gael Fraiteur and Kendall Miller (Gibraltar Software) speak with this month's LIVE Webinar guest Gary Short about overcoming the timeless challenges developers face in building fast and scalable systems.

Gary ShortGary is a frameworks technical evangelist for DevExpress, C# MVP, and frequent speaker at user groups and conferences throughout the UK, Europe and the U.S. -- including the upcoming DDD Scotland and TechEd conferences.

With presentation titles including How to Eat an Elephant, Data Mining the Social Web, and Credit Crunch Code, it's clear that Gary enjoys speaking about technical architecture.

In this month's LIVE Webinar you'll get a sneak peek at Gary's latest presentation, titled:

Asymptotics and Algorithms – What You’ve Forgotten Since University

Join the LIVE Webinar and discover:

  • The lost art of calculating which algorithm is more efficient than another, and...
  • Why managed environments, like .NET, may not know best.

Kendall MillerGiven the "big picture" performance theme of this month's Live Webinar, co-host Kendall Miller, will debut his latest presentation, titled:

Natural Laws of Software Performance

 

Join the LIVE Webinar and discover:

  • The natural laws that govern software performance
  • How technology has changed the tactics of high performance but is still at the mercy of these natural laws
  • How understanding these laws will help you create applications that scale without arcane tricks or endless hardware

Sign Up Now and Receive a Live Meeting URL Prior to Kickoff >>

Community
26 March 2011


CarlandRichard

For those of you who don’t yet subscribe to .NET Rocks! and its training video counterpart, dnrTV, you’re missing out on some wonderfully entertaining and informative talk shows.

Since 2002, Carl Franklin and Richard Campbell have been speaking with guests about programming in Microsoft .NET and, after nearly 650 episodes, show no signs of slowing down.

Gael was invited to be on .NET Rocks! in early February but, due to a bad phone line, he had to reschedule. Luckily both he and Carl attended this year’s NYC Code Camp, where they could finally sit down and record face-to-face. Or so he thought…

Listen to the first few minutes of the podcast to learn how Carl and Richard were finally able to record the show with Gael. Then, after you’ve had a good chuckle, continue listening to the podcast to learn more about programming with aspects.

DotNet Rocks

Listen to the podcast: http://www.dotnetrocks.com/default.aspx?showNum=640

Highlights include:

10:32 – What is an aspect?

12:10 – Using PostSharp for more than just Tracing and Logging

14:12 – Why having a bug in your aspect is safer than in the implementation of the manual line

20:20 – Two multithreading issues that can be solved using aspects

25:41 – Richard’s favorite example of AOP

36:43 – Static versus Dynamic AOP

40:08 – What’s next for PostSharp

Show the Code.

Gael also recorded a PostSharp demonstration with Carl on dnrTV. The shows on dnrTV are equally as entertaining as those on .NET Rocks! but with one very important difference: the code!

In this webcast-like format, guests are able to demonstrate technical topics in greater detail. That’s exactly what you’ll see in the recording with Gael as he dives deep into PostSharp – showing both common and advanced aspect usage.

dnrtv2

Watch the recording:  http://dnrtv.com/dnrtvplayer/player.aspx?ShowNum=0190

Highlights include:

02:10 – TraceArgumentsAspect : OnExceptionAspect

13:47 – TracePerformanceAspect : OnMethodBoundaryAspect

23:15 – CacheAttribute : MethodInterceptionAspect

45:57 – Undo/Redo

Special thanks to Carl and Richard for inviting Gael as a guest on both shows. And many thanks to all of you who watched the shows and provided feedback. Keep it coming.

Happy PostSharping!

-Britt

Community
23 February 2011


Have you heard all the talk about Microsoft AppFabric Caching lately?

According to Microsoft, “AppFabric Caching provides a distributed, in-memory, application cache service for Windows Azure and SQL Azure applications - giving high-speed access, scale, and high availability to application data.”

AppFabric Caching Dialog

What's more, these capabilities are provided entirely as a service (no installation or management of instances, dynamically increase/decrease cache size as needed).

In our very first Live Webinar, Gael Fraiteur (SharpCrafters Founder) and Kendall Miller (Gibraltar Software Co-Founder) speak with special guest Brian Prince (Microsoft) about AppFabric Caching capabilities and show you how to use PostSharp + Gibraltar to AppFabric enable your applications.

This webinar includes:

  • AppFabric concepts walkthrough
  • DIY caching versus caching with PostSharp
  • Advanced caching problems
  • Monitoring cache effectiveness and performance with Gibraltar
  • AppFabric futures
  • PostSharp futures
  • Q&A

This live webinar is free and kicks off Thursday, February 24th at 10:00am PT

 Signup for the Live Webinar here >>

**Those who signup will receive a Live Meeting URL prior to kickoff.

UPDATE: The recording is now available.

Community
15 February 2011


imageVSone kicks-off February 16th in Munich, Germany and will feature two days of presentations on Microsoft technologies including Silverlight, Life Cycle Management Application, SQL Server and data modeling, Azure, Web development, UI and devices, architecture and core programming, etc.

We recently caught up with Johannes Hoppe, who will speak at VSone on February 17th, invited him for a chat about his session on Aspect-Oriented Programming, and convinced him to give our German readers a sneak preview.

Britt: Why did you choose to speak about Aspect-Oriented Programming at VSone?

Johannes: The Clean Code movement has really taken off in Germany in the past few years and writing pragmatic clean code is something I’m passionate about. I shifted to aspect-oriented programming on some projects recently and have been amazed at the number of lines of code it has saved me. I wanted to share these insights with VSone attendees.

Britt: Why should VSone attendees care about AOP?

Johannes: For the same reason they care about clean code. AOP is an effective way to produce cleaner code and I believe it deserves to be used by more developers. Developers attend events like VSone because they’re looking for quick wins – learning things that they can implement right away – and my presentation is perfect for developers who want a quick introduction to Aspect-Oriented Programming. During the presentation I’ll show some production-ready aspects that I’ve prepared and make them available to attendees for download so they can start to use them right away in their own code.

Britt: What was your first experience with AOP?

Johannes: Early last year I was working on a project that had a tight deadline. My team had done unit tests and they all showed green but we still felt something wasn’t quite right. My boss told us to do a soft release and we sent 300 visitors (from a mailing list) to the website and the webserver nearly exploded.

We smartly decided not to go live with the project and instead looked at where the peaks were coming from. That was the first time I used AOP. We made a summary of the method runtimes and I used an aspect to log the method execution times to find the problem – a mistake on one of the most frequently used methods which made everything super slow – and later used a caching aspect to fix it. I’ve been addicted ever since.

Britt: Have you ever lectured about AOP to your students?

Johannes: No, not yet! My previous lectures have been about other topics but I’m hoping to introduce it in an upcoming “Software Architecture and Development” course. In the meantime my students are using “AOP- flavored” code without knowing it – for example the ASP.NET MVC HandleError Attribute and the Dependency Attribute from Unity. I like it when aspects are unobtrusive.

Britt: What will VSone attendees see in your presentation that’s not shown in your sneak preview?

Johannes: In addition to the introduction to AOP and showing how to make messy code clean again using common AOP patterns, attendees will see a live example of a logging aspect – I’ll show how easy it is to apply – followed by validation and caching aspects in real world scenarios. If there is time, I’d love to show my StackOverflow aspectthat finds unwanted recursion, including a real world disaster story of when it showed up in my life.

Britt: Where can our readers learn more about you?

My blog is a good start: http://blog.johanneshoppe.de/. I’m planning to publish some articles in print magazines soon, too. Readers can also go to my ADO.NET Unit Testable Repository Generator: http://repositorygenerator.codeplex.com/ which is something I’m quite proud of.

Britt: Which technologies interest you most and why?

Johannes: My daily work covers a lot of Microsoft technologies. At the moment I’m concentrated on ASP.NET MVC – the best MS platform for building websites, EXT.NET framework – a great tool for building RIA apps really fast, and Windows Phone 7 development. Microsoft gave me two Windows Phone 7s for ”free,” one as a finalist in the Imagine Cup and the other one I got for my Microsoft Student Partner Program efforts. Now I have to develop something for it.

Britt: Which sessions are you planning to attend at VSone?

There are so many good sessions at the same time it’s hard to decide which to attend. I will definitely go to Rouven Haban’s session “ASP.NET MVC in Practice.” In which he will talk about one of his recent projects of which I’m very interested. Thankfully his session is an hour before mine.

Britt: What’s this I hear about you and footbagging?

I was VERY into footbagging a few years ago and loved it so much that I built a footbag online shop http://www.footbag-shop.de/and later realized their potential as marketing vehicles http://www.promotion-footbags.de/. Footbagging is still one of my favorite outdoor games to play during breaks. Whenever I find some time, I like to make that little ball dance with my feet. I can’t wait for spring, it’s the best time for footbagging really!

Britt: You had me at “very.”

imageJohannes is a lecturer at SRH University Heidelberg and is very involved in the Microsoft Student Partner program on campus – running workshops and mentoring students. He has been working independently for over 10 years, is crazy about web design, and currently works on ASP.NET MVC and PHP projects. When he’s not working on projects or footbagging, Johannes keeps a blog about his adventures in lecturing at http://blog.johanneshoppe.de/.

Tutorial
26 January 2011


Marcus King recently released 3 screencasts showing how to address exception handling and caching.
We asked him to introduce his work in this guest post.

How often do I have to keep solving the same problem?  As developers we’ve all been there, each project we work on we have to do the same ole’ thing we’ve done a thousand times before.  Luckily in most cases there are good native features built into the language or third party frameworks that are available to reduce the tedious chore of writing basic code yet again.  However, there are a lot of times when OOP doesn’t provide us with a good way to solve a recurring problem.  I’m guessing since your reading the SharpCrafter’s Blog you see that this is the point where AOP steps in and fills the gap left by OOP.  I recently did a video tutorial on improving exception handing  using AOP via PostSharp.  Traditionally in applications we need to catch when certain exceptions are thrown and do something with the exception by either logging it, calling another workflow, wrapping the exception inside of another one, or simply swallowing the exception, or some combination of all.  Let’s say for example we have a class we use to call a remote web service to retrieve data for our application.

public class StockService
{
    public StockDetails GetStockDetails( string symbol )
    {
        try
        {
            //.... call to service
        }
        catch ( SoapException ex )
        {
            throw new StockServiceException( "Error Getting Details", ex );
        }
    }

    public decimal GetHistoricalPrice( string symbol )
    {
        try
        {
            //.... call to service
        }
        catch ( SoapException ex )
        {
            throw new StockServiceException( "Error Getting Historical Price", ex );
        }
    }

    public void AddToPortfolio( string symbol, int shares )
    {
        try
        {
            //.... call to service
        }

        catch ( SoapException ex )
        {
            throw new StockServiceException( "Error Adding to portfolio", ex );
        }
    }
}

Look how often we are repeating the same basic pattern.  We’re making our service call and wrapping any SoapException that is thrown in a custom StockServiceException.  Using PostSharp we are able to modularize our code and make the business logic of the StockService class look so much cleaner.

public class StockService
{
    [HandleException( SoapException, StockServiceException, 
"Error Getting Details" )] public StockDetails GetStockDetails( string symbol ) { //.... call to service } [HandleException( SoapException, StockServiceException,
"Error Getting Historical Price" )] public decimal GetHistoricalPrice( string symbol ) { //.... call to service } [HandleException( SoapException, StockServiceException,
"Error Adding To Portfolio" )] public void AddToPortfolio( string symbol, int shares ) { //.... call to service } }

All we need to do is create an attribute that derives from OnMethodBoundaryAspect that accepts three parameters in the constructor;  the type of exception to handle, the type of exception to wrap the caught exception in, and a message to give to the wrapped exception.

[Serializable]
public class HandleExceptionAttribute : OnExceptionAspect
{
    private Type _expectedException;
    private Type _wrapInException;
    private string _message;

    // Constructor that takes in variable parameters when the attribute is applied
    public HandleExceptionAttribute( Type expectedExeptionType, Type wrapInExceptionType, 
string message ) { _expectedException = expectedExceptionType; _wrapInException = wrapInExceptionType; _message = message; } // This method checks to see if the exception that was thrown from the method the // attribute was applied on matches the expected exception type we passed into the
// constructor of the attribute public override Type GetExceptionType( MethodBase targetMethod ) { return _expectedException; } // This method is called when we have guaranteed the exception type thrown matches the // expected exception type passed in the constructor. It wraps the thrown exception
// into a new exception and adds the custom message that was passed into the constructor public override void OnException( MethodExecutionArgs args ) { args.FlowBehavior = FlowBehavior.Continue; Exception newException = (Exception) Activator.CreateInstance(
_wrapInException, new object[] {_message, _expectedException} ); throw newException; } }

Another common problem set I solve with PostSharp is caching expensive method calls. I find myself repeating the same basic pattern in projects when I need to implement caching. I’m sure you’re familiar with it.

public Account GetAccount( int accountId )
{
    string cacheKey = string.Format( "GetAccount_{0}", accountId );

    Account account = Cache.Get( cacheKey );

    if ( account == null )
    {
        account = accountRepository.GetAccount( accountId );

        Cache.Add( cacheKey, account );
    }

    return account;
}

We build our cache key and check to see if the item is present if the cache. If it is we return the value pulled from the cache, otherwise we do the necessary work to retrieve/build the item to return and save it in the cache with the cache key we built so that the next time this method is called we can successfully pull the item from the cache. I’ve repeated this pattern over and over again, typically in a business layer when I need to retrieve data from an expensive resource like a database or a web service call or when I do complex logic to construct the object that I need to return. Luckily PostSharp provides a way to centralize all of the caching logic for me so I can concentrate on the business logic. The same method now looks like this

[Cache]
public Account GetAccount(int accountId)
{
    return accountRepository.GetAccount(accountId);
}

Once again I simply adorn the method with an attribute and it handles a lot of the repitive code. Here is what the Cache Attribute/Aspect code looks like.

public class CacheAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry( MethodExecutionArgs args )
    {
        string key = args.Method.Name + "_" + Cache.GenerateKey( args.Arguments );

        object value = Cache.Get( key );

        if ( value == null )
        {
            args.MethodExecutionTag = key;
        }

        else
        {
            args.ReturnValue = value;

            args.FlowBehavior = FlowBehavior.Return;
        }
    }

    public override void OnSuccess( MethodExecutionArgs args )
    {
        string key = args.MethodExecutionTag.ToString();

        Cache.Add( key, args.ReturnValue );
    }
}

In the OnEntry method I’m building the cache key and checking to see if the item exists in the cache and if so I’m not letting the target method complete and I’m returning the value pulled from cache. If no item was found in the cache, the execution of the target method proceeds and when the target method successfully executes the OnSuccess override is fired and the item is stored in the cache.

There are a lot more interesting things to do with the two areas of caching and exception handling so I would encourage you to check out my screen casts to learn more.

Exception Handling: http://www.sharpcrafters.com/media/tutorials/exception-handling

Cachinghttp://www.sharpcrafters.com/media/tutorials/caching-1

Going Further with Cachinghttp://www.sharpcrafters.com/media/tutorials/caching-2

 

marcus_king_image

Marcus King is a Software Engineer based in Louisville, KY. He has a broad IT background ranging from infrastructure security to software development, with years of experience working for many different sized companies, from Fortune 100 to small web startups. Marcus is passionate about performance tuning applications, developing solutions for highly scalable applications, plus is heavily involved in discovering and setting standards and best practices for software development. An Aspect-Oriented Programming (AOP) champion, Marcus regularly gives presentations on the topic. In his free time he writes applications for iPhone and Android and is on the executive committee of the codepaLOUsa developer conference in Louisville, KY.

Community
14 December 2010


Kendall Miller likes a good challenge.

As Principal at Gibraltar Software his day is filled with them. So imagine our surprise when, over drinks in London earlier this month, he told us how he recently turned the tables on a doubting customer with a challenge of his own:

“Give us 15 minutes to prove our value.”

The statement was so bold we just had to take out our recording equipment and get it on video. Watch to find out how Gibraltar turned the customer into a true believer, with the help of PostSharp, in under 15 minutes.

Do you have your own stories of exceeding customer expectations? Share them with us in the comments below.

-Britt

Filter by APML