Generic Type in Repository – .NET MVC Part

Step 4. Add the AOP mechanism in the GenericTypeController.cs file.

Fig 7. Add the SOP

[ExtendedAction]

Step 5. Check the Error List view. If it has no error messages, the solution project will build success.

Fig 8. Error List view

Step 6. Register the IGenericTypeRepository interface class and the GenericTypeRepository repository class file in UnityConfig.cs file under the web application project.

Fig 9 RegisterTypes method source code
public static void RegisterTypes(IUnityContainer container)
{
    container.RegisterType<IEnterprise_MVC_CoreRepository, Enterprise_MVC_Repository>();
    container.RegisterType(typeof(IGenericTypeRepository<>), typeof(GenericTypeRepository<>));
    container.RegisterType<LogAttribute>();
    container.RegisterType<ExtendedActionAttribute>();
}

Step 7. Try to run the web application under the debug model. You can see the backend logic transfer information on the Output view.

Fig 10. Running result under the debug model
Fig 11. Output view when app running.

Conclusion

We follow the .NET Core case uses the generic type method concepts to excuse the CRUD in .NET MVC cases. We can find out the .NET MVC case doesn’t use Microsoft.EntityFrameworkCore, but the .NET Core case use it, so the repository class’s CRUD method source code has a few difference. It doesn’t affect the CRUD methods and is based on projects on the difference using the package. When the web application runs under the debug model, the running result is successful without any error messages. We can put other entity model classes in IGenericTypeRepository, then executing the same as the repository class file and the CRUD methods.

Reference

Leave a Reply