Using server controls such as ObjectDataSource and GridView can indeed achieve very oop (however, I prefer to bind with Repeater, which is a little troublesome, and this is very fast)
However, if dependency injection is required for applications in a multi-layer framework, ObjectDataSource needs to be bound to the interface.
ObjectDataSource only supports classes and cannot instantiate interfaces. This will lead to the dependency of the multi-layer structure.
Google found it for half a day. You only need to use the following code.
Protected IBLLTestUser bll = BLLFactory. Create ("IBLLTestUser") as IBLLTestUser;
Protected void odsTestUser_ObjectCreating (object sender, objectperformanceeventargs e)
{
E. ObjectInstance = bll;
}
In this way, the instance can be passed in. However, interface binding still requires calling the original class to automatically generate interface elements, which is a bit uncomfortable, but this has little impact, because the lower layer changes, as long as it is injected, and it has nothing to do with the original, only facilitates page binding and generation. The interface fields of the gridview can be automatically generated together with the NHibernate object such as ilist <t>. All functions of the GridView can be generated, including settings of ObjectDataSource during paging, modification, deletion, and sorting.
The GridView can only be manually bound before ObjectDataSource is used. It is quite troublesome. After ObjectDataSource is used, the NHibernate object attribute corresponding to the GridView will be automatically brought out, as shown in comparison.