1

I am using asp.net mvc controller with constructor injected service IMyService. MyService (implements IMyService) uses some contextual information in its constructor. This contextual information supplied from different third party web site. Contextual information is required for creating MyService instance.

Controller's action filter uses some logic in order to determine, if this contextual information is available. If not, then request is redirected to another web site. The problem is, that controller constructor is called by IoC container before controller's filter. As a result MyService throws exception if contextual information is not provided.

How to workaround this situation?

UPD:
It seems that DelegatingHandler is a way to go.

1 Answer 1

1

If you need a quick workaround you could use remove the IMyService from your Constructor and instead add it in as a property of your controller and use your IoCs Service Locator to resolve it when it is needed by a method in the controller.

Sign up to request clarification or add additional context in comments.

1 Comment

To do this, I need to inject container into the constructor, it's not a good idea I think. But, only like workaround may be this is possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.