Using Unity configuration file, how to register FluentValidation Validator Implementation with concrete in a different assembly

I'm trying to register an implementation of FluentValidation.IValidator using a Unity configuration file.

The implementation of the Validator is in a referenced assembly. Not sure if this is of importance or not.

I have a WCF Host, with 2 references (for simplicity's sake)

  • ParameterInspector.dll
  • DataContracts.dll

The ParameterInspector.dll instantiates the Unity Container and tries to resolve the type. If you've worked with ParameterInspectors you'd know the type comes through as object, and I plan to use container.Resolve(obj.GetType())

The DataContracts.dll has the DataContracts and the Validator implementation. If you're familiar with FluentValidation, I've done the following:

public class MyValidator: AbstractValidator<MyDataContract>

I am now assuming, within the unity configuration file, somehow I have to register IValidator to somehow map to MyValidator implementation so that Unity knows how to construct the object?

Bearing in mind the the Unity container is instantiated in ParameterInspector.dll which has no reference to DataContracts.dll (the type comes through as object as per WCF pipeline architecture)

The unity configuration is obviously in the WCFHost web.config, and I assume I now have to instruct unity that FluentValidation.IValidator (MyDataContract residing in DataContracts.dll) is actually MyValidator.

I would prefer to do this in the configuration - but it works if I register it using code (which means ParameterInspector.dll needs a reference to DataContracts.dll) This works -

container.RegisterType<IValidator<MyDataContract>, MyValidator>(new ContainerControlledLifetimeManager());

But that means I need to reference DataContracts.dll from ParameterInspector.dll to resolve the Validator implementation and DataContract type which means its tied to that project and cannot be re-used for other DataContracts down the line. I would like ParameterInspector.dll to be generic as possible and Validator implementations to be configured in the host config.

Is this at all possible? If so, please point me in the right direction. Any other solutions are welcome as well. Thanks for taking the time to look at my question.


You should initialize your container in WCFHost, and pass it to ParameterInspector. WCFHost as composition root should know about all dependencies and compose them.

Need Your Help

Can the server use the same socket to send the response to the client? how?

c deadlock sockets

I am using Berkeley sockets (both: Internet domain and Unix domain) and I was wondering if the server can use the same sockets for reading the request and writing a response to the client. Or shoul...