Parameter Attributes used in the CWAB, Like StateDependencyAttribute

Mar 17, 2008 at 1:04 AM

I created some custom parameter attributes as well as use a few from the WCSF in my web applications. When I use them with Unity I get an error that really doesn't tell me too much. For example, if I use the StateDependencyAttribute in the constructor of one of my classes it fails miserably.

Am I missing a strategy or two that is used by the WCSF? I was thinking perhaps I needed to add some of the reflection-related strategies from the CWAB, but when moving one over, like the ConstructorReflectionStrategy, I noticed there are a few reflection classes, like IReflectionMemberInfo, that were apparently in the old version of ObjectBuilder that are not in the new version. I can certainly pull a few of those classes over, but I am wondering if this is even the best and only way to get this same functionality supported by Unity?

In general, will Unity support the parameter attributes in the CWAB and for which I have created several custom ones? Do you have any guidance on what it might take to get them to work?

Best Regards,

Mar 17, 2008 at 5:23 AM
Unfortunately, the strategy chain (and ObjectBuilder in general) has changed so much that the existing attributes won't work without rewriting them. That's the tradeoff you have to make to get an order of magnitude perf improvement. ;-)

The existing CWAB strategies all depend on the old reflection-driven approach, and they don't conform to the new API anyway, so moving them over really won't help any.

Looking at the code, it looks like I screwed up a little, and tightened down the functionality of the attributes a little too much. I need to tweak the implementation of the selector policies a little, and make the attribute responsible for creating the resolver objects. Should be a quick tweak, and then we should be able to write custom attributes that actually do something useful again. At that point, the implementation would be:

1) Write an implementation of IDependencyResolverPolicy that does whatever it is you want (look up in cache, http context, whatever)
2) Write an attribute that returns an instance of that policy.

Good catch. Fix should be in the next drop.