none
IOC Unity container usage RRS feed

  • Question

  • Hello,

    I have an asp.net web API. I am using Unity (5.11.1) for dependency injection. I would like to know if the bindings are correct.

    Here is my Unity Config:

    public static class UnityConfig
        {
            #region Unity Container
            private static Lazy<IUnityContainer> container =
              new Lazy<IUnityContainer>(() =>
              {
                  var container = new UnityContainer();
                  RegisterTypes(container);
                  return container;
              });
    
            /// <summary>
            /// Configured Unity Container.
            /// </summary>
            public static IUnityContainer Container => container.Value;
            #endregion
    
           /// </remarks>
            public static void RegisterTypes(IUnityContainer container)
            {
                // Transient Life Time manager!
                container.RegisterType<IGameServices, GameServices>().RegisterType<UnitOfWork>(new TransientLifetimeManager());
                container.RegisterType<IUserValidate, UserValidate>(new TransientLifetimeManager());
                
                
            }
        }

    Here <g class="gr_ gr_243 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="243" id="243">is</g> my GameServices:

    public class GameServices : IGameServices
        {
            private readonly UnitOfWork _unitOfWork;
    
            /// <summary>
            /// Public constructor.
            /// </summary>
            public GameServices(UnitOfWork unitOfWork)
            {
                _unitOfWork = unitOfWork;
            }
    
    ...

    Here is my UserValidate:

    public class UserValidate : IUserValidate
        {
            private readonly UnitOfWork _unitOfWork;
    
            /// <summary>
            /// Public constructor.
            /// </summary>
            public UserValidate(UnitOfWork unitOfWork)
            {
                _unitOfWork = unitOfWork;
            }
    ...


    Tuesday, July 23, 2019 11:32 AM

All replies