Dependency injection with Factory pattern sample code
public class SerializersFactory
{
    readonly ISerializer _iserializer;

    public SerializersFactory(ISerializer iserializer)
    {
        _iserializer = iserializer;
    }

    public string Serialize&lt;T&gt;() =&gt; _iserializer.SerializeToString&lt;T&gt;();

    public object Deserialize&lt;T&gt;() =&gt; _iserializer.DeserializeFromString&lt;T&gt;();
}


Sorry to burst your bubble, but... this isn't a factory. In fact, it's rather confusing what purpose it serves, given how that serializer is implemented:

    public nSerializerJson(string inputString, object inputObject)
    {
        if (inputString == null)
            throw new ArgumentNullException(nameof(inputString));

        if (inputObject == null)
            throw new ArgumentNullException(nameof(inputObject));

        InputObject = inputObject;
        InputString = inputString;
    }


It's very confusing why you need to specify both the serialized JSON string and the deserialized object for the constructor to not throw an ArgumentNullException. Actually, it's very hard to understand why one would even need this constructor.

It's the methods that need the parameters; having them at instance-level seems to make the whole thing more or less useless - and confusing.

What's the role of the &lt;T&gt; type parameter here?

public string SerializeToString&lt;T&gt;()
{
    return JsonConvert.SerializeObject(InputObject);
}


Oh, I see:


string SerializeToString&lt;T&gt;(); // Need &lt;T&gt; because of the Xml serializer.



Since when do implementations dictate what abstractions look like? That T is clearly begging for a method parameter there, of type T.



Seems you need to stop and ask yourself what you're trying to accomplish, and why. Your system has a dependency on Newtonsoft.Json; your serializer is essentially wrapping the Newtonsoft API... in some awkward way.

I would have used something like this:

public interface ISerializer
{
    string Serialize&lt;T&gt;(T deserialized);
    T Deserialize&lt;T&gt;(string serialized); // &lt;out T&gt;
}


And the implementation would be something like this:

public class JsonSerializer : ISerializer
{
    public string Serialize&lt;T&gt;(T deserialized)
    {
        return JsonConvert.SerializeObject(deserialized);
    }

    public T Deserialize&lt;T&gt;(string serialized)
    {
        return JsonConvert.DeserializeObject&lt;T&gt;(serialized);
    }
}


What else would you need? I think everything else you got here, is over-engineered fluff that can be removed. There's nothing to DI here, ISerializer is the dependency.

As for the factory, there's no need for one, since any type that needs an ISerializer can just tell the IoC container it needs one, by specifying an ISerializer parameter in its constructor.