Skip to content

ahansb/Template-Web-Api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Template-Web-Api

Template Web API with individual user accounts and without, ninject, automapper set up.

How to use it

  1. Open solution in VS
  2. Replace in files - TemplateWebApi with the desired name
  3. Rename the solution and all the projects - replacing TemplateWebApi with the desired name
  4. Rename all default namespaces and assembly names in all projects properties - replacing TemplateWebApi with the desired name
  5. Close VS
  6. Rename all the projects folders in Windows - replacing TemplateWebApi with the desired name
  7. Start the solution in VS
  8. All the projects can not be found
  9. Remove the project one by one and Add Existing Project to the folders by navigating to the desired one
  10. Select Web.Api to be starting project
  11. Delete all bin, obj and packages folders
  12. Build, Start, Done
  • Delete all bin, obj and packages folders - if something breaks, delete them again and restart the solution
  • If you do not follow the steps references will not be saved. They are:
    • TemplateWebApi.Common - none
    • TemplateWebApi.Data - TemplateWebApi.Data.Models
    • TemplateWebApi.Data.Common - TemplateWebApi.Data
    • TemplateWebApi.Data.Models - none
    • TemplateWebApi.Services.Data - TemplateWebApi.Data.Common, TemplateWebApi.Data.Models
    • TemplateWebApi.Web.Api - all
    • TemplateWebApi.Web.Infrastructure - none

Step-By-Step implementation

  1. Blank Solution - the name of the app
  2. Folders - Data, Services, Web
  3. Generating Projects
    • for Data - where browse to add \Data
      • the name of the app.Data
      • the name of the app.Models
Adding in Web the WebApi
  1. Delete

    • Scripts
    • Views
    • Fonts
    • Areas
    • AppData
    • Content
    • favicon
    • Project Readme
    • Bundle Config
    • Filter Config
    • Route Config
    • Home Controller
    • Values Controller???
  2. After build removing the unused from Global.asax

  3. From IdentityModels extract ApplicationUser to Data.Models

  4. Adding through Manage NuGet for solution adding EntityFramework and Microsoft.AspNet.Identity.EntityFramework for Data.Models and Data

  5. Adding references after build

  6. From IdentityModels extract ApplicationDbContext to Data

  7. Fix Usings and References

  8. Delete IdentityModels

  9. Package Manager Console - enable-migrations for Data

  10. Making public static class DatabaseConfig in App_Start with namespace without App_Start at the end

  11. In DatabaseConfig -
    public static void Initialize() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Configuration>()); } and fix the Configuration class into Migrations to be public

  12. Global.asax - DatabaseConfig.Initialize();

  13. DatabaseConfig - Initialize - ApplicationDbContext.Create().Database.Initialize(true);

  14. WebConfig - fixing connectionString

  15. IdentityConfig - for password length and so on

  16. For registering: POST - localhost:(your api)/api/Account/Register Headers - Content-Type - application/json Body - raw JSON - {"email":"ahansb@mail.com", "password":"123456", "confirmPassword":"123456"}

  17. For getting authorization: POST - localhost:(your api)/Token Body - x-www-form-urlencoded username ahansb@mail.com password 123456 grant_type password Access Token is received after the post of type Bearer

  18. AccountBindingModels - extract all classes with the same namespace

  19. AccountViewModels - extract all classes with the same namespace

  20. Fix all using in namespaces

  21. Adding Data.Common - with GenericRepository copy/paste from old projects and in Contracts IGenericRepository

  22. Adding in Services\TemplateWebApi.Services.Data

  23. Adding in Data.Models template object with user and in ApplicationUser collection ot templates. Adding Templates into ApplicationDbContext.

  24. Adding new TemplateController - Web API 2 Controller with actions, using Entity Framework. Adding [Authorization]

  25. Adding Project View Models - TemplateReques and Response view models

  26. Adding in Services.Data TemplatesService and ITemplatesService

  27. Installing Ninject.Web.WebApi.WebHost in Web.Api

  28. In NinjectWebCommon in RegisterServices - kernel.Bind().To();

  29. Adiing in TemplatesService and ITemplatesService Add function

  30. After Exception in NinjectWebCommon updating all 4 ninject

  31. If exception when try to start - Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'TemplateWebApi.Data.Models.ApplicationUser'., remove in ApplicationDbContext - public System.Data.Entity.DbSet<TemplateWebApi.Data.Models.ApplicationUser> ApplicationUsers { get; set; }

  32. Copy paste ninject register services -

  33. Adding IApplicationDbContext

  34. Adding through nuget ninject.extensions.conventions

  35. Adding using Ninject.Extensions.Conventions; in NinjectWebCommon

  36. Adding new project TemplateWebApi.Common with constants for assemblies

  37. In Repository to use IApplicationDbContext not DbContext and property Context

  38. Fixing TemplatesController with TemplatesService

  39. Installing Automapper in Web.API

  40. Making new project TemplateWebApi.Web.Infrastructure with mappings folder and installing Automapper:

    • AutomapperConfig
    • IHaveCustomMappings
    • IMapFrom
    • IMapTo
    • QueryableExtensions
  41. Register in Global.asax Automapper - var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(Assembly.GetExecutingAssembly());

  42. Making BaseController for automapper

  43. TemplatesController implement with automapper

About

Template Web API with ninject, automapper set up.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published