Closed rubenalves closed 4 years ago
Look at BookStore.Api project, BooksApiStartup.cs class - this shows how to setup all you need in Web app. You will have very similar startup class, and then in your ASP.NET core app (created from Visual Studio template) follow instructions here about startup class: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-3.1
reference your startup class in the call to UseStartup(...) method
Just one thing, to reiterate - do not try reuse directly your old controllers, the SlimApi thing is gone. You have to build 'real' ASP.NET-core controllers; VITA just provides some help with middleware and base API controller to inherit from
I am trying to use the examples and ajust them for my app and i am getting some problems, example: var loginAssembly = typeof(Vita.Modules.Login.Api.LoginController).Assembly; services.AddControllers() the AddControllers() is not available, am i missing some references? i made a exact copy of the examples code and cannot get it to work
just lookup from BooksApiStartup where it's coming from - add the package and 'using' if necessary. Looks like it is from Microsoft.ApNetCore.App - this is package ref, under Dependencies/Frameworks in the project in solution explorer (Frameworks I think is smth added in NetCore 3.1) , namespace Microsoft.Extensions.DependencyInjection, so you need this using. Btw, are you on Asp.Net-Core 3.1? double check what's your platform
I have looked from BooksApiStartup for hours and canot get it working, i am using asp.net-core 3.1 and still canot get it to compile on my machine. I have googled for hours on examples of web api and did not get it. I think that the solution is to add like a server app with 1.9.3 and the main app with 3.02 The SlimControllers where very fantastic. Thanks for your help.
wait, are you saying WebTests is not running or not compiling?!
I have copied the webtests to my solution made the changes necessery for my code but canot get the services.AddControllers() to work, canot find a way to it to compile.
so webTests compile and run. then just check the refs (packages) between WebTests and yours. Your are missing package/assembly reference. Check the Dependencies, all subfolders, find what's different. Try the following - create new ASP.NET-core project, with Web APi option selected (in a wizard when you create new project), and try again using AddControllers and resolving namespaces Running 1.9.3 for web server - I don't think it's a good idea.
or just create new app and try to call AddControllers there, just one line
I found the problem, the main app is using .net framework and i canot change the console aplication to work with .net core, do probably i have to use a standard webapi instead.
console app? as Web app? sounds confusing maybe I misunderstand, but... don't try to 'change' existing app (retarget it); You need to create it from scratch for .NETCore, there are all kinds of apps there to choose from. then copy and adjust all source files
My solution uses the full .net, the main app uses winforms, the server app is a concole app that uses asp.net owin self host to work as a server for REST comunications as a windows service or independant console app, but i canot change it to .net core because the main solution is .net full. With the slimcontroller it worked very well, so it is doable only problem is find out how :) Thanks.
I think you are a bit confused. The VS solution does NOT have any assigned framework, only individual projects; you can have some on full .NET fx, and some libs on .NET standard, and others on .NETCore Next, the WebTests project is in fact a console app that does self-hosting of ASP.NETCore, and you can run it as console from VStudio - try it! So this I think is exactly what you need, to match your old running model
Is there any dowloadable example of an application that uses ApiController ? I was using SlimApi before and iam trying to recreate a mini server i hade in my aaplication for reading some recors and edit them I hade to register the api like this RegisterControllerType(typeof(PedidosController)); ApiConfiguration.RegisterControllerType(typeof(ArtigosController)); I have seen the Examples but i canot undestand them, they are only tests and not real aplications tests. Can you drive me to the right direction? Tank you very much.