Auto Register using Unity Loader exception

226 Views Asked by At

I have recently added unity to my project and I am looking for a cleaner way to register classes.

I have got to the point where it auto registers fine but attempts to auto register everything. Including Mircrosoft.Web.Mvc which includes several classes that are sealed not allowing it to be registered and therefore throwing a loader exception.

Any help with a standard auto register or exclude.

Any configuration I try even creating my own customer controller factory leads to this exception.

{"Method 'GetControllerSessionBehavior' in type 'Microsoft.Web.Mvc.MvcDynamicSessionControllerFactory' from assembly 'Microsoft.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.":"Microsoft.Web.Mvc.MvcDynamicSessionControllerFactory"}

All help appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

I wrote my own exclusion.

            .ExcludeAssemblies(x =>
                {
                    if (!x.GetName().FullName.StartsWith("Microsoft."))
                    {
                        return x.GetName().Name.Equals("Microsoft");
                    }
                    return true;
                })