Post by zawe on Apr 25, 2023 6:06:30 GMT
Hi there,
I was wondering whether you could advise me on combining Zenject and EnhancedScroller. What I mean by this is ... let's say I have a cell :
public class MyCellView : EnhancedScrollerCellView{
[Inject]
private MyDependency myDependency;
public override void SetData(Data data){
// do whatever
}
}
However when I create create my cells in GetCellView() delegate method of IEnhancedScrollerDelegate class, the method GetCellView() is called on EnhancedScroller 👇. This method either recycles old cell or, creates a new cell via instantiating it from prefab directly. This prevents injection of any dependencies marked with [Inject].
public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex){
var myCellView = scroller.GetCellView(myCellViewPrefab) as MyCellView;
myCellView.SetData(_data[dataIndex]);
return cellView;
}
At this moment it would be great if the cell could be created from Factory (which allows the injection of dependencies) or recycled if possible...
Any take / existing implementation/ ideas on this would be appreciated 🙏
------
I have one solution where I use MyCellView only as an empty container and in CellViewInstantiated() (this is the point atfer cell got created not just recycled) I actually create cell child view from factory and add it as a child to MyCellView (which is a an empty container)
private void CellViewInstantiated(EnhancedScroller scroller, EnhancedScrollerCellView cell) {
var cellWithDependencies =. _cellFactory.Create();
cellWithDependencies.transform.SetParent(cell.transform, false);
}
I was wondering whether you could advise me on combining Zenject and EnhancedScroller. What I mean by this is ... let's say I have a cell :
public class MyCellView : EnhancedScrollerCellView{
[Inject]
private MyDependency myDependency;
public override void SetData(Data data){
// do whatever
}
}
However when I create create my cells in GetCellView() delegate method of IEnhancedScrollerDelegate class, the method GetCellView() is called on EnhancedScroller 👇. This method either recycles old cell or, creates a new cell via instantiating it from prefab directly. This prevents injection of any dependencies marked with [Inject].
public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex){
var myCellView = scroller.GetCellView(myCellViewPrefab) as MyCellView;
myCellView.SetData(_data[dataIndex]);
return cellView;
}
At this moment it would be great if the cell could be created from Factory (which allows the injection of dependencies) or recycled if possible...
Any take / existing implementation/ ideas on this would be appreciated 🙏
------
I have one solution where I use MyCellView only as an empty container and in CellViewInstantiated() (this is the point atfer cell got created not just recycled) I actually create cell child view from factory and add it as a child to MyCellView (which is a an empty container)
private void CellViewInstantiated(EnhancedScroller scroller, EnhancedScrollerCellView cell) {
var cellWithDependencies =. _cellFactory.Create();
cellWithDependencies.transform.SetParent(cell.transform, false);
}