Last week, Donald Belcham joined Gael Fraiteur on the PostSharp Live Webinar to talk about one of the largest challenges faced on Brownfield projects: adding project-wide functionality to a codebase.

Attendees learned:

Options for adding non-functional requirements

Areas of risk when adding non-functional requirements

Use of IL Weaving to add non-functional requirements

IL Weaving granularity

Watch the recording and learn the techniques and tools you can use to add functionality to brownfield codebases.

Q&A

Q: In a greenfield development scenario that is already using IoC, are there any advantages to using the existing container to implement AOP features vs. using IL weaving?

A: The primary benefit of IL weaving is the types of aspects you can create. With Interception you can only wrap public virtual methods. IL weaving allows you to add aspects to events, field variables, property getters/setters, methods, etc.

Q: I have a brownfield project that's 20 years old and was developed using ASP, VB6.0, Windows Services and JavaScript. How do I migrate it to green field?

A: A good place to start is the case study we wrote with the team at Mitchell International, who faced a similar scenario. It demonstrates how they used PostSharp to build several aspects to facilitate integration between their new and old applications. The project was daunting but by adding Activity Logging, Exception Handling, Performance Counters, Thread Dispatching and Data Sync functionality project-wide the team saved from having to write thousands of lines of code.

Q: I used PostSharp OnMethodBoundaryAspect and TransactionScope to replace transaction management in a very large brownfield data access project (SQL transactions). There was a lot of duplicate code removed and all done successfully now - it's much cleaner. The only issue was around code where a rollback transaction was forced (not rolled back implicitly as the result of an exception). Is there a more comprehensive example (beyond the basic TransactionScope enter, exit, dispose, complete) of how other people have gone about this?

A: You could have a static method InvalidateTransaction that would set a thread-static boolean field. In the OnEntry advice, check that field to decide whether the transaction should be committed or rolled back.

Q: How will Roslyn change the AOP landscape in .NET languages like C# and VB?

A: Good things would happen if the compilation pipeline could be made customizable. It could improve Intellisense and compiler support for aspects that introduce new interface implementations, methods, or even full types. Unfortunately, there's no indication this will happen any time soon. Except for these possibilities, Roslyn is not going to be a game changer.

Next week’s guest on the PostSharp Live Webinar is Donald Belcham, a senior software developer, independent contractor, trainer, speaker and PostSharp MVP.

On Thursday, August 29th (09:00 PT, 12:00 ET, 16:00 GMT) Donald will speak about one of the largest challenges faced on Brownfield projects: adding project-wide functionality to a codebase.

The difficulty comes from the tangled nature of Brownfield codebases. Finding all the locations where the functionality is needed is one thing. The bigger issue is, how do you add the new functionality without altering existing APIs or, worse, introducing defects?

This webinar will look at the techniques and tools that you can use to add functionality to less than inviting codebases.

Attendees will learn:

Options for adding non-functional requirements

Areas of risk when adding non-functional requirements

Use of IL Weaving to add non-functional requirements

IL Weaving granularity

If you’ve ever wanted to learn how to better tame brownfield codebases using AOP be sure to sign-up for the next PostSharp live webinar.

Last week, Alex Papadimoulis joined Gael Fraiteur on the PostSharp Live Webinar to talk about NuGet, the popular open-source library package manager for .NET, and show how it helps developers escape from "dependency hell" while discovering new third-party libraries.

Attendees learned:

how developers are successfully using NuGet;

why PostSharp chose NuGet for deployment management;

what deployment management pitfalls to watch out for; and

when to consider solutions like private repositories.

Watch the recording and learn how to leverage NuGet and private repositories to improve your enterprise architecture.

Q&A

Q: When you install the NuGet plugin by default it is configured to pull from the public repository. How do you prevent users from pulling packages from this public NuGet repository? Is this a specific configuration change?

A: What you have to do from a training standpoint is instruct developers to add a package source. Go to package management settings, uninclude the official package source, and add in your own corporate library. There is no good way to prevent developers from doing it themselves, so it's important to monitor your packages.config file for changes to it to ensure a bad package isn't added.

Q: How do you deal with scenarios where two packages depend on the same third package, but they depend on different versions of that third package? Visual Studio will only include one of the versions, and you will get a runtime failure.

A:This becomes tricky. NuGet attempts to add a binding redirect to mitigate the problem, but it can cause more problems than benefits. My advice is to monitor the versions that are added and that you're redirecting appropriately.

Q: Is it possible to configure NuGet for projects independently of Visual Studio solutions? What if projects appear in multiple solutions?

A: NuGet works fine if you keep your configs simple but can complex things can get a little hairy depending on your configuration. has a packages.config file, and some of the default locations for the packages file

Q: Can standard MS packages (e.g. MVC 4 bits) required by the new project dialog be routed via a private NuGet repository to make the selection / deselection of the public NuGet repository in the developer machine?

A: Yes. Select the Package Manager option in Visual Studio, where the available Package Sources are displayed, and select the source you want to use. NuGet will use whatever package source you select rather than the public source.

Q: What's the best way to enable package restore on a bulid server?

A: Package restore adds a folder to your Visual Studio solution and does all sorts of weird things with it. We recommend users not use NuGet package restore and instead have a NuGet install as part of your build server plan. We recommend this to our customers since NuGet package restore doesn't work with PostSharp. Create a build step that includes calling NuGet install before calling MS build for every file package.config you find in your source tree. It's much more reliable.