質問

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.

役に立ちましたか?

解決 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.

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top