Code weaving and aspects to improve separation of concerns

TAB

Aspect-oriented programming is an expansion on the principle of separation of concerns. It aims to extract cross-cutting concerns, such as authorisation or logging, that are often intermingled with other code.

The implementation of these aspects in C# often takes the form of custom attributes that can be added to classes or methods, resulting in code being injected or “woven” into the assembly at build time. This both improves separation of concerns and cuts down on repetitive boilerplate code.

The MarketPlace, Ami and ContrOCC Remote teams have all been using aspects via the PostSharp framework. However, the ContrOCC Remote team discovered that PostSharp has dropped support for Xamarin since v4.3, so they have looked elsewhere.

Fody is working well with Xamarin and .NET Standard. ContrOCC Remote has started by using it for guarding against nulls. Fody has matured significantly in recent years and has a huge number of add-ons. Plus, unlike PostSharp, it’s open source.

If aspects or code weaving might be useful to you, have a look at Fody.

TAB Logo

Leave a Reply