2

I have some dependencies inside of my aspects, and I'd like use an IoC container to manage the lifecycle of these dependencies.

My first thought is that introducing a constructor which takes one more argument than the most specific constructor in the type would be a good way to solve this.

I can't seem to find a way to do this however, and I was wondering if A) this is possible, and B) Whether there are better solutions to this problem.

Khanzor
  • 4,830
  • 3
  • 25
  • 41

1 Answers1

0

You need to use Introduction. See the following tutorials.

http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-14-e28093-Introducing-members-and-interfaces-Part-1.aspx

http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-15-e28093-Introducing-members-and-interfaces-Part-2.aspx

ILovePaperTowels
  • 1,445
  • 2
  • 17
  • 30
  • Thanks, the problem with that approach is that I need to introduce a constructor, based on constructors that already exist in the type. It strikes me that perhaps this has a better solution (it seems a bit complicated). – Khanzor Jan 24 '12 at 07:41
  • You would need to reflect on the targets to determine the constructor's profile but then you'd have to write the code for the aspect. You can't do this with postsharp (dynamically generating the method profile). You could use T4 template to read through the classes and write the aspect with the correct constructor to inject (not as hard as it sounds) but I'd have to just suggest you find a better way of doing whatever it is you want to do. If it's dependency injection you're looking for then use property injection, not constructor injection. It would be so much easier. – ILovePaperTowels Jan 24 '12 at 15:02