Reputation: 39068
I've noticed that it's been bothering me lately that when I'm advancing into a project, I always end up with a bunch of attributes that decorate the method declarations in the interface but also a different set of decorating the method implementations.
The latest instance is this WCF I'm working with and there, I'm only going to have a single implementing class. Still, some attributes populate the interface, while others do the class. Is that considered bad coding style?
More specifically - can/should all the attributes be moved into the implementing class definition when working with WCF?
Upvotes: 1
Views: 105
Reputation: 8502
Specific to WCF:
You can't move all the attributes to Implementing class alone, as the WCF Contract
is defined by the interface and it is the interface that is exposed to the WCF Clients which are used for discovery of the WCF services and metadata.
Also, Attributes
are used by the .Net runtime using reflection and they are used to discover and apply metadata to various AttributeTargets
which include interface
, class
etc.
So, I think it is Ok to use Attributes
in both interfaces and classes and not considered a bad practice provided the .Net runtime
requirement is dependent on the target where they are used.
Upvotes: 2