Fluentnhibernate AttributePropertyConvention

By Deathraven on Tuesday 4 June 2013 11:04 - Comments are closed
Category: Software Development, Views: 2.884

Fluentnhibernate's AttributePropertyConvention is great. It allows you to use the conventions feature, but still allows you to customize where needed.

Unfortunatly they dont work on reference types. You can fix that by creating your own AttributeReferenceConvention type like so.


C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
public abstract class AttributeReferenceConvention<T> : IReferenceConvention, IReferenceConventionAcceptance where T : Attribute {
         public void Accept(IAcceptanceCriteria<IManyToOneInspector> criteria) {
             criteria.Expect(property => Attribute.GetCustomAttribute(property.Property.MemberInfo, typeof(T)) as T != null);
        }
        
        public void Apply(IManyToOneInstance instance) {
             var attribute = Attribute.GetCustomAttribute(instance.Property.MemberInfo, typeof(T)) as T;

            Apply(attribute, instance);
        }

        protected abstract void Apply(T attribute, IManyToOneInstance instance);
    }



In my case I wanted to override the lazy loading settings for a specific reference. Now I can do that like this:


C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class EagerLoadingConvention : AttributeReferenceConvention<EagerLoadingAttribute>
    {
        protected override void Apply(EagerLoadingAttribute attribute, IManyToOneInstance instance) {
           instance.Not.LazyLoad();
            instance.Fetch.Join();
        }
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class EagerLoadingAttribute : Attribute
    {
        public EagerLoadingAttribute()
        {

        }
    }

Cross module communication with Autofac Part 1

By Deathraven on Saturday 23 April 2011 11:30 - Comments (2)
Category: Software Development, Views: 4.155

The next series of blogs is going to be about creating an system that allows cross module communication while preventing said module(s) from having a direct dependency on each other.

Read more »

The age of NuGet

By Deathraven on Tuesday 18 January 2011 20:20 - Comments (2)
Category: Software Development, Views: 3.886

The age of NuGet has dawned. No more unknown frameworks that escape your clutches. No more ploughing through obscure installation documentation to try and integrate said framework into your own project.

It all became as easy as point and click.

Read more »

Extending MVC Contrib MenuBuilder

By Deathraven on Tuesday 28 September 2010 09:37 - Comments (4)
Category: MVC, Views: 5.514

Today i am going to talk about MVCContrib's MenuBuilder. I started using it in a project of mine because it did exactly what i wanted it to and it saved me the effort of writing something like that myself.

Read more »

Spark and MvcContrib and the 'The type or namespace name 'FluentHtml' does not exist' error

By Deathraven on Monday 30 August 2010 12:17 - Comments (1)
Category: MVC, Views: 5.767

So its been a while since my last post. The past year getting my .Net 3.5 and WCF certification and switching to a new job have kept me rather busy. But perhaps more on that in a different post.

Lately I have been busy with asp.net mvc and my favourite viewengine Spark.
However it seems there is a problem in the spark compiler. Whenever
the app pool recycles, the spark compiler doesn't seem to load all of
the referenced assemblies, resulting in compilation errors.

Read more »