You are missing a few abstractions here. You're missing an general abstraction over your data types and an abstraction for creating implementations of those data types:
// In your core layer
public interface IDataType {
void ProcessData();
}
public interface IDataTypeFactory {
IDataType Create(DataRecordType dataRecordType);
}
// In Bootstrapper class
resolver.RegisterInstance<IDataTypeFactory>(new DataTypeFactory(resolver));
resolver.RegisterType<IDataType1, DataType1>();
resolver.RegisterType<IDataType2, DataType2>();
resolver.RegisterType<IDataType3, DataType3>();
private sealed class DataTypeFactory : IDataTypeFactory {
private readonly IUnityContainer container;
public DataTypeFactory(IUnityContainer container) {
this.container = container;
}
public IDataType Create(DataRecordType dataRecordType) {
switch (dataRecordType) {
case DataRecordType.dataType1:
return this.container.Resolve<IDataType1>();
case DataRecordType.dataType2:
return this.container.Resolve<IDataType2>();
case DataRecordType.dataType3:
return this.container.Resolve<IDataType3>();
default:
throw new InvalidEnumArgumentException();
}
}
}
What you can see is that the code for creating implementations is moved to the factory. Now the remaining application code can be comes something like this:
// Main flow...outwith bootstrapper
IDataType dt = this.dataTypeFactory.Create(dataRecordType);
dt.ProcessData();
The IDataType1, IDataType2 and IDataType3 are now only used in the bootstrapper and have become redundant (or at least, redundant with the code you presented), so you could even remove them all together and change the bootstrap logic to the following:
// In Bootstrapper class
resolver.RegisterInstance<IDataTypeFactory>(new DataTypeFactory(resolver));
resolver.RegisterType<DataType1>();
resolver.RegisterType<DataType2>();
resolver.RegisterType<DataType3>();
private sealed class DataTypeFactory : IDataTypeFactory {
private readonly IUnityContainer container;
public DataTypeFactory(IUnityContainer container) {
this.container = container;
}
public IDataType Create(DataRecordType dataRecordType) {
switch (dataRecordType) {
case DataRecordType.dataType1:
return this.container.Resolve<DataType1>();
case DataRecordType.dataType2:
return this.container.Resolve<DataType2>();
case DataRecordType.dataType3:
return this.container.Resolve<DataType3>();
default:
throw new InvalidEnumArgumentException();
}
}
}