Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Amr Younis 13 posts 94 karma points
    Oct 18, 2016 @ 17:34
    Amr Younis
    0

    object reference not set to an instance of an object

    Hi Dears,

    i post you this error before Here https://our.umbraco.org/forum/developing-packages/80623-object-reference-not-set-to-an-instance-of-an-object but i found the problem but i cannot solved enter image description here

    this code below is the reason when register dependencies

            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
            builder.RegisterType<Ta2healDbContext>().As<IUnitOfWork>().InstancePerReques();
            builder.RegisterType<SubjectService>().As<ISubjectService>().InstancePerLifetimeScope();
            builder.RegisterType<SectionService>().As<ISectionService>().InstancePerLifetimeScope();
            builder.RegisterType<LessonService>().As<ILessonService>().InstancePerLifetimeScope();
    
            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    

    and this when i stop some code of register dependencies

    enter image description here

    it's work when i do this into register dependencies code

           var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
            builder.RegisterType<Ta2healDbContext>().As<IUnitOfWork>().InstancePerRequest();
    
            builder.RegisterType<SubjectService>().As<ISubjectService>().InstancePerLifetimeScope();
            builder.RegisterType<SectionService>().As<ISectionService>().InstancePerLifetimeScope();
            builder.RegisterType<LessonService>().As<ILessonService>().InstancePerLifetimeScope();
            // Set the dependency resolver to be Autofac.
            //var container = builder.Build();
            //var resolver = new AutofacWebApiDependencyResolver(container);
            //GlobalConfiguration.Configuration.DependencyResolver = resolver;
            //DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    

    but code that i stopped make some problem to me so i ask you if anyone have idea what can i do to solve this problem?

Please Sign in or register to post replies

Write your reply to:

Draft