Asp.Net 5 MVC 6 Startup.cs Dismantling the assembly in beta

I am working on an e-commerce site using Asp.Net 5 and MVC6 after Onion Architecture (OA) so that we have free communication between the layers. I also want to cancel the startup code in my own assembly, and not have it in the MVC project.

In beta, it was very easy to move Startup.cs to the class library (Bootstrapper), as described here . One interesting fact using the above approach is that I do not need to reference the Bootstrapper assembly from the MVC project. At runtime, hosting under IISExpress, through assembly scan, he was able to find the Bootstrapper node mentioned in the Microsoft.AspNet.Hosting.ini file. This was possible by specifying a location in global.json

{ "projects": [ "Source/Projects","Source/Bootstrapper" ], "sdk": { "architecture": "x64", "runtime": "clr", "version": "1.0.0-beta7" } } 

The Bootstrapper project will have a link to all other projects, such as Infrastructure, Services, etc., to enable dependency injection.

The reason not to refer to the Bootstrapper project in the MVC project, following the rules of the Onion architecture, is to refuse access to the infrastructure code directly from the MVC project. So all this was fine until I switched to Beta8 this morning.

Since the hosting model was changed from IIS to Kestrel, I had to reorganize the global.json and project.json files as shown below

global.json

 { "projects": [ "Source/Projects","Source/Bootstrapper" ], "sdk": { "architecture": "x64", "runtime": "clr", "version": "1.0.0-beta8" } } 

project.json

 { "dependencies": { "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8", "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8", "....", "....", }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel" } } 

After making the above changes, I started getting the following error, regardless of whether I run it using the dnx command or directly through Visual Studio

Internal server error .InvalidOperationException A type named "StartupDevelopment" or "Startup" was not found in the assembly 'EcommerceMvcApp'. at Microsoft.AspNet.Hosting.Startup.StartupLoader.FindStartupType (String startupAssemblyName, IList diagnosticMessages) at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureStartup () at Microsoft.AspNet.Hosting.Internal.HostingEngine.ppernsensepplication) AspNet.Hosting.Internal.HostingEngine.BuildApplication ()

It turned out that I should specify the configuration file or inline arguments for the web command, as described here . After executing this sentence, I tried to run the application, and this time I started getting the error below

System.IO.FileNotFoundException Failed to load file or assembly "Bootstrapper" or one of its dependencies. The system cannot find the file specified. in System.Reflection.RuntimeAssembly._nLoad (AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark & ​​stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFelectrelection AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark & ​​stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Booleanssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss0cr0c= To_Configuration_ResourceReferenceMessage_Assembly_reference_reference StackCrawlMark & ​​stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) in System.Reflection.Assembly.Load (AssemblyName assemblyRef) in Microsoft.AspNet.Hosting.Star tup.StartupLoader.FindStartupType (String startupAssemblyName, IList diagnosticMessages) with Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureStartup () at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureApplicationServices.erstern.ervices.erstern.erstern.erstern.erstern.erstern.ersternerningerhnter.ernostherning.ernserning.ersternerningervice.ernsernternerhenterpowerstring.ernsernternerhunter.nost .BuildApplication ()

The solution requires adding a link to the Bootstrapper project in the MVC project, and it works. However, this defeats the goal of having a separate Bootstrapper assembly in the first place.

The question is why it cannot find the Bootstrapper assembly, as was done in Beta7, using the sources specified in the "projects" in global.json, or is it a new hosting model that ignores global.json? Is there a way to specify the location of the launch assembly?

Update 1

I just want to emphasize that in Beta7 it also works using the "dnx" command for Microsoft.AspNet.Server.WebListener and Microsoft.AspNet.Server.Kestrel.

 "commands": { "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5004 --config wwwroot/Microsoft.AspNet.Hosting.ini", "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5004 --config wwwroot/Microsoft.AspNet.Hosting.ini" } 

However, the dnx command (using the Microsoft.AspNet.Hosting.json file) does not work for both servers in beta. If someone is interested that this has something to do with the IIS Helios component in Beta7, this is not the case. I'm confused why build search stops working in Beta8

Update 2

Here is the stack trace that I get when I try to start Beta8 using IISExpress. It looks like he is trying to find the assembly in the dnx bin folder.

System.IO.FileNotFoundException: Failed to load file or assembly "Bootstrapper" or one of its dependencies. The system cannot find the file specified. File name: 'Bootstrapper' at System.Reflection.RuntimeAssembly._nLoad (AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark & ​​amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFunder Boundleousset Boundleople Thunder Boolean throwOnFileNotFound Bounceleput Boundleaptound Boolean Reflection.RuntimeAssembly.nLoad (AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark & ​​amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFoundNameRameLasserlementlesserlieflefer supper evidence building Security, RuntimeAssembly reqAssembly, StackCrawlMark & ​​stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) in System.Reflection.AssemblyameRembly (Assembly ) in Microsoft.AspNet.Hosting.Startup.StartupLoader.FindStartupType (String startupAssemblyName, IList`1 diagnosticMessages) with Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureStartup () in Microsoft.AspNet.Hosting.Internal.HeringAser at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication ()

=== Prebinding status information === LOG: DisplayName = Bootstrapper (Partial) WRN: Partial binding information was provided for assembly: WRN: Assembly name: Bootstrapper | Domain ID: 1 WRN: A partial binding occurs when only part of the display name of the assembly is displayed. provided. WRN: This may cause the binder assembly to load incorrectly. WRN: It is recommended that you provide a fully defined textual identity for the assembly; WRN: consists of a simple name, version, culture, and public key token. WRN: See White Paper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and general solutions to this problem. LOG: Appbase = File: /// C: /Users/sshassan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta8/bin/ LOG: Initial PrivatePath = NULL. Call Node: (Unknown). === LOG: This binding begins with the default load context. LOG: Application configuration file not found. LOG: Using the host configuration file: LOG: Using the machine configuration file from C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Config \ machine.config. LOG: The policy does not currently apply to the link (closed, user, partial, or location binding). LOG: Attempting to load a new URL File: /// C: /Users/sshassan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta8/bin/Bootstrapper.DLL. LOG: attempt to load a new URL File: /// C: /Users/sshassan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta8/bin/Bootstrapper/Bootstrapper.DLL. LOG: attempt to load a new URL File: /// C: /Users/sshassan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta8/bin/Bootstrapper.EXE. LOG: attempt to load a new URL File: /// C: ./Users/sshassan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta8/bin/Bootstrapper/Bootstrapper.EXE

Maybe if I started dnu publish and post it in IIS, it will work, but that means that I will have to publish it every time I make a change

+5
source share
2 answers

I had a similar problem. It seems that we do not want to refer to the user interface level at the Infraestructure level (we are very strict), not even to solve the dependency problem.

This may be possible with late binding (I just heard about it), but I think you should read this article . This basically means that the root composition cannot be reused, and for each application there should be one (for example, one for UI.Web, another for UI.Console, etc.).

It also answers my question about what DI resolution has in UI.Web, but you need a different user interface, say, a console (answer: it is advisable to make a DI anoreter resolution in the console, but it will have its own which are related to how it actually works console application ).

I hope to give you a good moment to clarify this issue.

+1
source

The format of the host configuration file has changed from INI to Json. Try the following:

 { "Hosting:Application": "Bootstrapper", } 

Also see this issue .

0
source

Source: https://habr.com/ru/post/1234131/


All Articles