Post

Community Attribute Builder final

If you are working with Relate+ platform most probably you are using entities attributes to attach some additional info to particular entity type. This is a great way to extend built-in functionality but however involved a bit of manual work:

  • You have to define attribute for each of the entity in Relate+ administrative UI (which honestly speaking could be made more user friendly).
  • You have to refer to the attribute via stringly-typed interface.

Latter for me is most embarrassing.

1
instance.SetAttributeValue("attributeName", attributeValue);

This approach could give you few real scenarios where such is unacceptable:

  • When you will margin for a grammar error when typing attribute name – that could be discovered only during runtime.
  • You cannot use static code analysis tools. Like to search for all attribute usages.
  • You cannot use some of the refactoring tools –> like rename attribute name.
  • You can easily change type of the attribute and forget about code that uses that, effect –> runtime error(s).
  • Use cannot leverage all the power of Visual Studio (for instance to provide Intellisense over available attributes)

So therefore I created package that should relief tasks with Community entity’s attributes – Community Attribute Builder.

There were already some posts on this topic here, here and there. Latest version (1.0) is out and this is just a summary of what’s supported.

  1. Describe community entity’s attributes in code. Those attributes defined in metadata class are synced during application start-up and added to the target entity:
1
2
3
4
5
6
[CommunityEntity(TargetType = typeof(IUser))]
public class SampleAttributeMetadata
{
    [CommunityEntityMetadata]
    public virtual IList<SampleType> SampleAttribute { get; set; }
}
  1. Limit scanning of the assemblies:
1
2
3
4
5
6
7
8
9
10
11
12
13
<configuration>
  <configSections>
    <section name="entityAttributeBuilder" type="Geta.Community.EntityAttributeBuilder.EntityAttributeBuilderConfiguration, Geta.Community.EntityAttributeBuilder" />
  </configSections>

  <entityAttributeBuilder>
    <scanAssembly>
      <add assembly="EntityAttributes" />
      <remove assembly="RemoveAssembly" />
    </scanAssembly>
  </entityAttributeBuilder>

</configuration>
  1. You can set or get entity’s attribute value(s) using strongly-typed interface.
1
2
var metadata = instance.AsAttributeExtendable<SampleAttributeMetadata>();
metadata.SampleAttribute = null;
  1. Support for strongly typed queries
1
2
3
var query = new UserQuery();
var qmetadata = query.AsMetadataQuery<SampleAttributeMetadata>();
qmetadata[m => m.SampleAttribute] = new StringCriterion { Value = "the attribute value" };
  1. Added support for IList type attributes. You can assign via local variable assignment and modification or using line modifications.
1
2
3
4
5
6
7
var entity = instance.AsAttributeExtendable<SampleAttributeMetadata>();

// getter
var collection = entity.SampleAttribute;
collection.Add(new SampleType(100));
// setter
entity.SampleAttribute = collection;

or you can use more convenient syntax:

1
2
var entity = instance.AsAttributeExtendable<SampleAttributeMetadata>();
entity.SampleAttribute.Add(new SampleType(100));

Rename, deletion and content migration for the community entity attributes need to me done manually.

Can be found here (or search by “community” in NuGet package manager).

Hope this helps!

[eof]

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.