Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top