0

I'm trying to detect whenever a property setter is called (and run some code as a result). I could write a method into the setter of every property:

private string name;
public string Name
{
    get { return name; } set { OnChange(this); name = value; }
}

But this gets tedious when you have hundreds of properties. Is NInject capable of intercepting setter methods?

In terms of purpose, I'm trying to track every object which changes.

FBryant87
  • 4,273
  • 2
  • 44
  • 72
  • 1
    Can this question help you? https://stackoverflow.com/questions/24593289/ninject-strange-intercept-to-inner-set-properties – pix Aug 03 '17 at 15:15
  • That works! Though I've just realised I'd need to create all my trackable objects with NInject so that they're within the kernel - is that likely to severely hamper performance if there's say, 5000 of them? – FBryant87 Aug 03 '17 at 15:42
  • 1
    Ninject is a DI Container. DI Containers are meant to build up object graphs consisting of application Components (the classes that contain the application's behavior). The `Name` property however seems to be part of an object that consists of runtime data (such as a DTO or Domain entity). Your DI Container should now _nothing_ about them. If you need to use interception on runtime data, don't abuse your DI Container. Use your interception library directly. – Steven Aug 03 '17 at 17:10

0 Answers0