I have 2 controllers, both require an object of the MySettings
type which represents a set of settings. Each controller needs its custom set of settings. In order to do that at the registration of the module I create 2 settings objects by hand and put them both to the container. Question is how can I specify that each controller is supposed to be injected with its own pre-defined custom-initialized instance of the MySettings type?
UPDATE:
Now there is an ugly workaround in place that basically renders Autofac useless as all resolving is done by hand:
public class MyModule : Module {
protected override void Load(ContainerBuilder builder) {
builder.Register(context => {
var productControllerSettings = new MyListSettings(
pageSize: 20,
orderBy: "Name",
orderDirection: OrderDirection.Ascending
);
// and hell of other parameters that I need to resove
// by hands by doing context.Resolve<...> for each of them
var productController = new ProductController(
productControllerSettings
/*, the reset of parameters */
);
return productController;
});
builder.Register(context => {
var userControllerSettings = new MyListSettings {
pageSize: 20,
orderBy: "LastName",
orderDirection: OrderDirection.Ascending
};
var userController = new UserController(
userControllerSettings
/*, the rest of parameters resolved by calling context.Resolve<> by hands */
);
return userController;
});
}
}
There must be a better way of doing it I hope.
UPDATE2:
Another way of getting around this shortfall is to make 2 new classes of settings based on MySettings class. This way each instance uniquely corresponds to a class and Autofac can easily resolve it. I don't want to do just for the sake of making Autofac work.