Search code examples
c#asp.net.netcode-behindsimple-injector

Simple Injector Web Forms


Okay so I have a UI layer and a BLL layer.

namespace BLL 
{
   public class User : IUser
   {
        public void DoSomething(){}
   }
   public interface IUser
   {
        void DoSomething();
   }
   public static class TypeRegistry
   {
        public static void RegisterTypes(Container container)
        {
            container.Register<IUser, User>(Lifestyle.Singleton);
        }
    }
}

namespace UI
{
     public partial class Login : System.Web.UI.Page
     {
          private IUser user;
     }
}

I can't figure how to get user to not be null. I have tried making a constructor but that caused an error

    public Login(IUser user){ this.user = user;}

Compilation Error : Login does not contain a constructor that takes 0 arguments


Solution

  • This link helped me get the answer:

    https://simpleinjector.readthedocs.org/en/latest/wpfintegration.html

    Similar to @Steven's link

    https://simpleinjector.readthedocs.org/en/latest/windowsformsintegration.html