In .NET 4.7.2 Microsoft introduced the ability to use constructor injection in WebForms through the use of HttpRuntime.WebObjectActivator
as seen here
The example given is in C#. I am working on a legacy VB.NET app that is in the process of being modernized. We would like to use constructor injection over the property injection we had been planning on using because it is more canonical.
However, when I attempt to give a WebForm a parameterized constructor I get the following error.
(BC30387) Class 'testpage_aspx' must declare a 'Sub New' because its base class 'TestPage' does not have an accessible 'Sub New' that can be called with no arguments.
This seems to be due to the way that VB.NET handles constructors and inheritance. With the way VB.NET handles constructors is having parameterized constructors in a VB.NET WebForms project even possible?
Did you target the app to 4.7.2 in web.config? Something like below. Constructor injection can't be used in Page/Controls in website project(the project type that doesn't have vbproj file), since the base type of the Page/Controls are unknown when generating code for Pages/Controls.
<httpRuntime targetFramework="4.7.2"/>
Edit: Here is a blog post about how to use Unity in the exiting WebForms app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With