Hi, I'm running into a problem in a tutorial I'm following along with in the book "Pro ASP.NET MVC 3 Framework". The code examples are written in C#, but I'm coding everything in VB. In the code under the "NinjectControllerFactory" file, I'm getting an error
in the line I marked using the word "ERROR" in bold. Visual Studio is underlining EFProductRepository and giving me this error:
Type argument 'SportsStore.WebUI.Concrete.EFProductRepository' does not inherit from or implement the constraint type 'SportsStore.WebUI.Abstract.IProductRepository'.
I'm really not sure how to fix this error, and I would appreciate anyone's help. I marked each individual code file that might relate with a bold header.
NinjectControllerFactory
Imports System
Imports System.Web.Mvc
Imports System.Web.Routing
Imports Ninject
Imports System.Linq
Imports SportsStore.WebUI.Abstract
Imports SportsStore.WebUI.Concrete
Imports SportsStore.WebUI.Entities
Namespace SportsStore.WebUI.Infrastructure
Public Class NinjectControllerFactory
Inherits DefaultControllerFactory
Private ninjectKernel As IKernel
Private Sub AddBindings()
ERROR--> ninjectKernel.Bind(Of IProductRepository).To(Of EFProductRepository)()
End Sub
Public Sub New()
ninjectKernel = New StandardKernel()
AddBindings()
End Sub
Protected Overrides Function GetControllerInstance(ByVal requestContext As RequestContext, ByVal controllerType As Type) As IController
Return If(controllerType Is Nothing, Nothing, DirectCast(ninjectKernel.Get(controllerType), IController))
'TODO: Warning!!!, inline IF is not supported ?
End Function
End Class
End Namespace
IProductRepository
Imports System.Linq
Imports SportsStore.WebUI.Entities
Namespace Abstract
Public Interface IProductRepository
ReadOnly Property Products() As IQueryable(Of Product)
End Interface
End Namespace
EFProductRepository
Imports System.Linq
Imports SportsStore.WebUI.Abstract
Imports SportsStore.WebUI.Entities
Namespace Concrete
Public Class EFProductRepository
Public Class EFProductRepository
Private context As New EFDbContext
ReadOnly Property Products As IQueryable(Of Product)
Get
Return context.Products
End Get
End Property
End Class
End Class
End Namespace
This should implement - IProductRepository which is missing. also why you have duplicate nested class definition.
Public Class EFProductRepository
Implements IProductRepository
Private context As New EFDbContext
ReadOnly Property Products As IQueryable(Of Product)
Get
Return context.Products
End Get
End Property
End Class
Thanks, your advice pointed me in the right direction and here is what ended up fixing it:
Imports System.Linq
Imports SportsStore.WebUI.Abstract
Imports SportsStore.WebUI.Entities
Namespace Concrete
Public Class EFProductRepository
Implements IProductRepository
Private context As New EFDbContext
Public ReadOnly Property Products As System.Linq.IQueryable(Of Entities.Product) Implements Abstract.IProductRepository.Products
Get
Return context.Products
End Get
End Property
End Class
End Namespace
Leschandrew
Member
1 Points
11 Posts
Type argument... does not inherit from...
Dec 30, 2012 02:45 AM|LINK
Hi, I'm running into a problem in a tutorial I'm following along with in the book "Pro ASP.NET MVC 3 Framework". The code examples are written in C#, but I'm coding everything in VB. In the code under the "NinjectControllerFactory" file, I'm getting an error in the line I marked using the word "ERROR" in bold. Visual Studio is underlining EFProductRepository and giving me this error:
Type argument 'SportsStore.WebUI.Concrete.EFProductRepository' does not inherit from or implement the constraint type 'SportsStore.WebUI.Abstract.IProductRepository'.
I'm really not sure how to fix this error, and I would appreciate anyone's help. I marked each individual code file that might relate with a bold header.
NinjectControllerFactory Imports System Imports System.Web.Mvc Imports System.Web.Routing Imports Ninject Imports System.Linq Imports SportsStore.WebUI.Abstract Imports SportsStore.WebUI.Concrete Imports SportsStore.WebUI.Entities Namespace SportsStore.WebUI.Infrastructure Public Class NinjectControllerFactory Inherits DefaultControllerFactory Private ninjectKernel As IKernel Private Sub AddBindings() ERROR--> ninjectKernel.Bind(Of IProductRepository).To(Of EFProductRepository)() End Sub Public Sub New() ninjectKernel = New StandardKernel() AddBindings() End Sub Protected Overrides Function GetControllerInstance(ByVal requestContext As RequestContext, ByVal controllerType As Type) As IController Return If(controllerType Is Nothing, Nothing, DirectCast(ninjectKernel.Get(controllerType), IController)) 'TODO: Warning!!!, inline IF is not supported ? End Function End Class End Namespace IProductRepository Imports System.Linq Imports SportsStore.WebUI.Entities Namespace Abstract Public Interface IProductRepository ReadOnly Property Products() As IQueryable(Of Product) End Interface End Namespace EFProductRepository Imports System.Linq Imports SportsStore.WebUI.Abstract Imports SportsStore.WebUI.Entities Namespace Concrete Public Class EFProductRepository Public Class EFProductRepository Private context As New EFDbContext ReadOnly Property Products As IQueryable(Of Product) Get Return context.Products End Get End Property End Class End Class End NamespaceCPrakash82
All-Star
18284 Points
2841 Posts
Re: Type argument... does not inherit from...
Dec 30, 2012 03:03 AM|LINK
This should implement - IProductRepository which is missing. also why you have duplicate nested class definition.
Public Class EFProductRepository Implements IProductRepository Private context As New EFDbContext ReadOnly Property Products As IQueryable(Of Product) Get Return context.Products End Get End Property End Classignatandrei
All-Star
134960 Points
21632 Posts
Moderator
MVP
Re: Type argument... does not inherit from...
Dec 30, 2012 03:04 AM|LINK
1. Duplicate definition
2.
Leschandrew
Member
1 Points
11 Posts
Re: Type argument... does not inherit from...
Dec 30, 2012 03:26 AM|LINK
Thanks, your advice pointed me in the right direction and here is what ended up fixing it:
Imports System.Linq Imports SportsStore.WebUI.Abstract Imports SportsStore.WebUI.Entities Namespace Concrete Public Class EFProductRepository Implements IProductRepository Private context As New EFDbContext Public ReadOnly Property Products As System.Linq.IQueryable(Of Entities.Product) Implements Abstract.IProductRepository.Products Get Return context.Products End Get End Property End Class End Namespace