# Hangfire job throws Autofac exception even though job class is not managed by Autofac

**URL:** <https://discuss.hangfire.io/t/hangfire-job-throws-autofac-exception-even-though-job-class-is-not-managed-by-autofac/488>\
**Category:** question\
**Created:** [December 27, 2014, 10:53am UTC](https://discuss.hangfire.io/t/hangfire-job-throws-autofac-exception-even-though-job-class-is-not-managed-by-autofac/488 "2014-12-27T10:53:06Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![gusrin](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@gusrin](https://discuss.hangfire.io/u/gusrin)\
**Post date:** [December 31, 2014, 2:01pm UTC](https://discuss.hangfire.io/t/hangfire-job-throws-autofac-exception-even-though-job-class-is-not-managed-by-autofac/488/5 "2014-12-31T14:01:27Z")

</div>

Sure thing!

The cshtml for the email template looks like this:

```
To: @Model.To
Subject: @Model.Subject

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
    <div>
        Hello @Model.Person

        Your new password is: @Model.NewPassword

        Regards
    </div>
</body>
</html>

```

The entire IoC config looks like this:

```
public class IocConfig
    {
        private static WeakReference<IContainer> _container;

        public static void RegisterDependencies()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModule<AutofacWebTypesModule>();
            builder.RegisterType<UnitOfWork>().As<IUnitOfWork>();

            //My business logic services like this example below
            builder.RegisterType<BusinessLogicService>().As<IBusinessLogicService>();

            builder.RegisterType<MemoryCacheWrapper>().As<IMemoryCache>();
            builder.RegisterType<TypeLessMvcFileHelper>().AsSelf();

            //Our context is disposed after each request
            builder.RegisterType<DbContext>().As<IDbContext>().InstancePerRequest();

            builder.Register(b => NLogLogger.Instance).SingleInstance();
            builder.RegisterModule(new IdentityModule());

            builder.RegisterModelBinderProvider();
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());

            var container = builder.Build();
            _container = new WeakReference<IContainer>(container);

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));          
        }
    }
```

---

_[View the full topic](https://discuss.hangfire.io/t/hangfire-job-throws-autofac-exception-even-though-job-class-is-not-managed-by-autofac/488)._
