It's a bit of a hack, but you can do something similar by setting ContractResolver in the JsonSerializerSettings settings. In this case, using Autofac:
var builder = new ContainerBuilder(); builder.RegisterInstance(myService); var container = builder.Build(); var settings = new JsonSerializerSettings { ContractResolver = new AutofacContractResolver(container), };
and then in the converter:
var jsonContract = serializer.ContractResolver.ResolveContract(typeof(IMyService)); var service = (IMyService)jsonContract.DefaultCreator();
Thus, you really do not enter the service into the converter, but at least you can access it without a specific dependency. In addition, you do not use the same Autofac container as your application, but create a new one. Not perfect, but it's something :)
source share