Asp.net C# DDD - Implementing Web Api

Asked

Viewed 663 times

1

I’m developing a DDD structure system with Simple Injector.

When developing the WEB API, the data returned from the BD is null.

In other tests performed in the MVC view, the same data is returned normally. The problem is the deployment of dependency injection, only I can’t identify where.

Implementation of the Simple Injector

    [assembly: WebActivator.PostApplicationStartMethod(typeof(App_Start.SimpleInjectorWebApiInitializer), "Initialize")]

namespace Api.App_Start
{
    using System.Web.Http;
    using SimpleInjector;
    using SimpleInjector.Integration.WebApi;
    using SimpleInjector.Lifestyles;          

    public static class SimpleInjectorWebApiInitializer
    {
        /// <summary>Initialize the container and register it as Web API Dependency Resolver.</summary>
        public static void Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            InitializeContainer(container);
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }

        private static void InitializeContainer(Container container)
        {
            IoC.Bindings.Start(container);
        }
    }
}

Ioc

namespace IoC
{
    public class Bindings
    {
        public static void Start(Container container)
        {
            //Infrastrutura
            container.Register<IRepositoryManager, RepositoryManager>();
            container.Register<IWorkUnit, WorkUnit>();
            //container.Register(typeof(IBaseRepositories<>), typeof(BaseRepositories<>), Lifestyle.Scoped);
            container.Register(typeof(IUsuarioRepositories), typeof(UsuarioRepositories), Lifestyle.Scoped);
            container.Register(typeof(ISistemaRepositories), typeof(SistemaRepositories), Lifestyle.Scoped);

            //Dominio
            container.Register(typeof(IUsuarioDomain), typeof(UsuarioDomain), Lifestyle.Scoped);
            container.Register(typeof(ISistemaDomain), typeof(SistemaDomain), Lifestyle.Scoped);

            //Service Locator
            ServiceLocator.SetLocatorProvider(() => new SimpleInjectorServiceLocatorAdapter(container));
        }
    }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.