I have a situation where I created a factory method to create an object. However, the object has boilerplate code that needs to be executed before the object is created. Fixing this part of the design is beyond the scope of this question.
In addition, when an object is created, the status display is updated on the screen. This requires that this status indicator be created earlier and be visible, and the application must be operational before creating this object. It is passed to the factory as a dependency.
I am using v3.1.4.143 StructureMap.
So here is what I will do in the normal world (pre-IoC):
GraphicsInterface GetGraphics()
{
VideoDevicesList.GetVideoDevices();
VideoDevice device = ...;
return new GraphicsInterface(device, featureLevels.FL5);
}
It seems pretty simple, but ideally I would like to convey this graphic object through injection, as it will be needed in many places.
, factory, . .
new Container(obj =>
{
For<Func<IStatusDisplay, GraphicsInterface>>
.Use<Func<IStatusDisplay, GraphicsInterface>>(GetGraphics);
}
, GraphicsInterface . GraphicsInterface. , GraphicsInterface, , GetVideoDevices , , StructureMap , _getGraphicsFactory() ( , , ).
GetInstance, GetVideoDevices:
_container
.With<VideoDevice>(device)
.With<FeatureLevel>(FeatureLevel.FL5)
.GetInstance<Graphics>();
...
, - , ?