0

We are using DotNet Remoting for our application server and also using StructureMap. How do go about setting up proper dependency injection inside the remoting objects so that my code is no longer littered with dependency lookup code like this?

PolicyEntity policy = ObjectFactory.GetInstance<IPolicyDataAccessor> ().FindByPolicyId (policyId);

To be clear, I want to be able to declare a property on my remoting object and have StructureMap inject into it. Then I can just write.

PolicyEntity policy = PolicyDataAccessor.FindByPolicyId (policyId);

Any help will be appreciated.

Jehof
  • 34,674
  • 10
  • 123
  • 155
Johann Strydom
  • 1,482
  • 14
  • 18

2 Answers2

2

You shouldn't inject any dependencies on anything you send over the wire. You should only send data packages (DTOs) over the wire and handle those messages locally using services (that you resolve through your DI framework).

Steven
  • 166,672
  • 24
  • 332
  • 435
  • The DI will all happen for intenal use inside the remoting object and the properties will not be used by the caller of the object. All data transfer is happening via DTOs. The remoting objects are all setup for single call. – Johann Strydom Jun 03 '13 at 14:12
0

Since it's not very convenient to create the remoted object from the ObjectFactory, the easiest way is to let the remoting server construct the object as normal and, inside the object constructor which it will call, let the remoted object inject itself with its dependencies using;

ObjectFactory.BuildUp(this);

That will inject all dependencies, just as if the object was created from the ObjectFactory to begin with.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294