C# Domain Specific Implementations: Unity and Generics
<p>I have created components containing domain specific information in my application e.g. ImportManager, ExportManager etc
I'd like each component to operate as an isolated unit but I'm coming a little undone by my use of generics - when used with dependency inject (unity).
I have the following base object defined in a library.</p>

<pre><code>public class ImportManager : IImportManager
{
    [Dependency]
    public IImportSettings Settings {get;set;}
}
</code></pre>

<p>The idea here being that I define a base class that implements standard functionality.
I then create a client-specific implementation which changes the standard behaviour slightly. This class has its own implementation and settings implemented in a different assembly as follows:</p>

<pre><code>public class CustomImportManager : ImportManager, ICustomImportManager
{
}
</code></pre>

<p>The difference with this implementation is that I'd like to load ICustomSettings into the CustomImportManager - not ISettings.
I could just register the dependency in my bootstrapper and it would load fine but then I would have to cast the settings object every time I use it in CustomImportManager.
Alternatively, I could define a generic parameter on IImportManager:</p>

<pre><code>public interface IImportManager&lt;TSettings&gt; where TSettings: ISettings
{
    [Dependency]
    public TSettings Settings {get; set}
}
</code></pre>

<p>Unfortunately this will require me to add the generic parameter to every class that defines this interface as a property leading to classes having masses of generic parameters.
In the example below, the facade could potentially implement 10+ components depending on its requirements meaning I'd have to define a TObject for every component - also making it very difficult to use itself.
    public class Facade
    {
        [Dependency] IImportManager ImportManager {get; set; }
    }</p>

<p>Does anybody have any ideas on how I may get around this?</p>

<p>Thanks in advance</p>