Kgn-web
Kgn-web

Reputation: 7555

The type or namespace name 'UnitOfWork' could not be found

I am new to IOC & unity.

Below is my Bootstraper class in WebApi project.

 public static class Bootstrapper
{
    public static void Initialise()
    {
        var container = BuildUnityContainer();

        DependencyResolver.SetResolver(new UnityDependencyResolver(container));

        // register dependency resolver for WebAPI RC  
        GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
    }

    private static IUnityContainer BuildUnityContainer()
    {
        var container = new UnityContainer();

         //here I am getting error <UnitOfWork> could not be found.
        container.RegisterType<IRegistrationService, RegistrationService>().RegisterType<UnitOfWork>(new HierarchicalLifetimeManager());

        return container;
    }  
}

Here is my package.config

<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
<package id="CommonServiceLocator" version="1.3" targetFramework="net45" />
<package id="EntityFramework" version="6.0.1" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />
 <package id="Microsoft.AspNet.WebApi" version="5.0.0" targetFramework="net45" />
 <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.HelpPage" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
<package id="Respond" version="1.2.0" targetFramework="net45" />
<package id="Unity" version="4.0.1" targetFramework="net45" />
<package id="Unity.WebAPI" version="5.2.3" targetFramework="net45" />
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
</packages>

I have installed

 Install-Package Unity.WebAPI

But I am getting the error (title).

I have referred the below link to get started.

http://www.c-sharpcorner.com/UploadFile/1492b1/restful-day-2-inversion-of-control-using-dependency-injecti/

What I am missing here to get rid of this error.

Upvotes: 1

Views: 631

Answers (1)

Nkosi
Nkosi

Reputation: 247123

According to the article that is a model/class created in the project of the example article.

If you checked the link to the previous article in the that series you would have seen where they defined that class.

/// <summary>  
/// Unit of Work class responsible for DB transactions  
/// </summary>  
public class UnitOfWork : IDisposable   { ... }

I advise that you start from the beginning of that tutorial. You will miss a few steps if you start in the middle.

Upvotes: 2

Related Questions