Hendry Luk — Sheep in Fence

March 9, 2012

SheepAspect Preview 3

Filed under: Software Development — Hendry Luk @ 1:43 am
Tags: ,

This is not a massive release or anything. The idea is to push new changes rapidly to the public to attract early feedbacks, especially because this Preview3 release comes with a good set of new features and improvements that I genuinely feel very excited about. Many of these changes are based on feedbacks I have received from early adopters. So thanks to everyone who has shared their inputs.

What’s New

There is no significant changes on the underlying SheepAspect framework itself. This release is more of implementing new functionalities and natural progression of the feature-set of the library. Some of these new features are:

  1. The most significant new feature in Preview3 release is the Mixins support. With the new [DeclareMixin] advice, you can now statically add interface implementations to existing classes. I will write have written the details of this in a separate post.
  2. We also now have [DeclareAttributes] advice attribute. With this advice, you can statically add attributes to existing types, methods, properties, fields, and constructors. This will also be covered in the upcoming posts.
  3. IAspectAware interface, so you can now intercept when your aspects get instantiated by AspectRuntime so you can execute some initialisation routine. Again, this will be covered in the upcoming posts.
  4. A more complete set of pointcut implementations. Preview-2 advices could only target methods, properties, and instructions (method-calls, field gets/sets). In preview-3, they can also target types, constructors, fields, and property getters/setters. Events are only partially supported at the moment.
  5. Intellisense documentation. I understand that SheepAspect has a very steep learning curve. It can be overwhelming for users to get started or to figure out what each attribute does. In this Preview 3 release, most of SheepAspect’s public API is well documented.
    image10image9
  6. In Preview 2, SheepAspect required pdb files of all target binaries (so that SheepAspect can preserve debuggability of your weaved binaries). This has caused a problem for users who do not have pdb files of their target binaries. In Preview 3, pdb files are optional.

Get It Now

As usual, SheepAspect Preview3 is installable from NuGet: https://nuget.org/packages/SheepAspect. SheepAspect-Query-Analyzer for Preview-3 version is still due to come soon, and will be downloadable separately on the SheepAspect homepage.

UPDATE: SheepAspect-Query-Analyzer is now always included when you install via NuGet, under the Tools directory within the SheepAspect package folder.

About these ads

12 Comments »

  1. [...] Preview-3 was released today, and one of the most important new features is Mixins. In Preview-2, there were only one [...]

    Pingback by SheepAspect: Mixin « Hendry Luk — Sheep in Fence — March 9, 2012 @ 5:27 am | Reply

  2. Thanks for your great work. Sheep.Aspect has been a huge improvement for our development. Can you give a brief description on how to use the [DeclareAttributes] attribute? Currently I have a need for adding some attributes to properties in generated code and an aspect for this could be of great help. I tried to figure it out by myself, but unfortunately I doesn’t work. Everytime the compiler crashes with

    Error : The best overloaded method match for ‘Mono.Cecil.ModuleDefinition.Import(System.Type)’ has some invalid arguments

    Do you have any idea, what could be wrong? The pointcut works when I use it with e.g. an around advice.

    Comment by Christoph Emonds — November 22, 2012 @ 10:50 am | Reply

    • Hi Christoph, thanks for the support.
      You’re right, DeclareAttribute syntax is really not the most obvious to work out. As a general pointer, the best place to figure out the usage syntax of certain SheepAspect API is usually the documentation comments included on each attribute, which provides some basic syntax and usage examples that will hopefully give some starting point.

      As for [DeclareAttribute], here’s an example of an aspect to declare [Transactional(IsolationLevel = "READ COMMITTED", Scope = "RequiredNew")] attribute to all public methods within service classes:

      [SingletonAspect]
      public class InjectTransactionalAttributeAspect
      {
         [SelectMethods("Public & InType:Name:'*Service'")]
         public void ServiceMethodsPointcut(){}
      
         [DeclareAttributes("ServiceMethodsPointcut")]
         [Transactional(IsolationLevel = "READ COMMITTED", Scope = "RequiredNew")]
         public void AddTransactionalAttribute(){}
      }
      

      (Taken from the sample project included in the project repository: http://sheepaspect.codeplex.com/SourceControl/changeset/view/80132#1293278)

      Hope that helps, but please do let me know if you have any difficulty. In the meantime I will fix the cryptic error message. If you could send me the sample code snippet you used to produce the error, that would be really helpful.

      Comment by Hendry Luk — November 22, 2012 @ 11:42 am | Reply

      • I had a look into the code and defined the aspect as follows:

        [Aspect]
        public class JsonExportPropertyFilterAspect
        {
        [SelectProperties("InType: 'ambiHome.Model.MyClass' & Name: 'MyProperty'")]
        public void SpecifiedProperties() { }

        // TODO DeclareAttributes doesn't work with aspect compiler :-(
        //[DeclareAttributes("SpecifiedProperties")]
        [JsonIgnore]
        public object DeclareJsonIgnoreAttribute { get; set; }
        }

        The class with the property is simple:


        namespace ambiHome.Model
        {
        ///
        /// Description of MyClass.
        ///
        public class MyClass
        {
        public string MyProperty { get; set; }
        }
        }

        If it helps I can provide you with a sample project.
        Thank you for helping me with this issue.

        Comment by Christoph Emonds — November 22, 2012 @ 12:00 pm

  3. Thanks for providing the sample code. Everything looks to be fine. I tried the exact same code and can’t seem to produce the error, however I have a strong suspicion that it might be down to the Mono.Cecil version. Could you clarify the exact version of Mono.Cecil.dll version referenced by the project (as well as its file-system path as provided by nuget)? Also, what .net version are you using?

    UPDATE: I managed to get the error, which is apparently caused by declaring the [DeclareAttribute] advice on a property (public object DeclareJsonIgnoreAttribute {get; set;}), as opposed to be on a method (which is currently the only supported way to define this advice). Though I can see why you need to define it on a property in your case.
    I will fix this bug shortly. Unfortunately I can’t seem to see any possible workaround at the moment. Thanks for reporting it, I’ll ping you when I get this fixed.

    Comment by Hendry Luk — November 22, 2012 @ 12:44 pm | Reply

    • I use .NET 4.0. The packages.config contains Mono.Cecil in version “0.9.5.3″, but the version in the file packages/Mono.Cecil.0.9.5.3/lib/net40/Mono.Cecil.dll says “0.9.5.0″. I’m a little bit confused since Mono.Cecil is not a reference within my project.

      Comment by Christoph Emonds — November 22, 2012 @ 1:00 pm | Reply

    • Thanks a lot :-) Great news.

      Comment by Christoph Emonds — November 22, 2012 @ 1:02 pm | Reply

      • I have published the fix to Nuget. Please update your SheepAspect Nuget package (to 0.3.0.5). Please let me know if it resolves your issue.

        Comment by Hendry Luk — November 22, 2012 @ 2:08 pm

  4. Now it works like a charm :) Thank you for your great support, saved me a lot of headaches.

    Comment by Christoph Emonds — November 22, 2012 @ 3:18 pm | Reply

    • I’m glad that solved your issue :)

      Comment by Hendry Luk — November 23, 2012 @ 12:07 am | Reply

  5. And why don’t you update codeplex download section? When I first saw the project in my codeplex search results i thought it’s dead or about to be die because latest downloadable version related to 2011 year.

    Comment by Anton Kulaga — December 26, 2012 @ 2:11 pm | Reply

    • Hi Anton. I stopped publishing the binaries via the download page since Nuget, because I didn’t see the need for the otherwise complicated installation instructions, which can be a bit discouraging to most users.

      Comment by Hendry Luk — December 26, 2012 @ 10:20 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: