UnityMvcActivator或global.asax

Sea*_*man 6 .net asp.net-mvc unity-container

我有两个问题。我安装了Unity和Unity MVC软件包开始对其进行调查。通过注册一些类型,我得到了一些简单的控制器构造函数注入,因此运行顺利。我注意到,由于以下原因,甚至在global.asax被击中之前,它就已经开始了:

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(example.org.UnityMvcActivator), nameof(example.org.UnityMvcActivator.Start))]
Run Code Online (Sandbox Code Playgroud)

问题1:此语法的名称甚至是什么?某种将类型/方法附加到其他地方的嵌入式汇编引用?我以前从未见过。

问题2:UnityMvcActivator具有与上面的[assembly]行相对应的Start()和Shutdown()方法,其中的后一项仅在容器上进行处理。Start()的核心元素是调用:

DependencyResolver.SetResolver(new UnityDependencyResolver(UnityConfig.Container));
Run Code Online (Sandbox Code Playgroud)

是否存在一个令人信服的原因(例如dispose()这样的UnityMvcActivator存在),或者它可能需要尽早启动,或者只是为了让我开始而做的简单脚手架,我也可以将SetResolver()行放入其中我的global.asax,然后删除此类?