Base solution for your next web application

Activities of "acrigney"

I made another post on this topic but it hasn't been approved yet, lets wait for that.

Best Regards, Alistair

I am actually trying to use a Windsor IHttpControllerActivator now.

using Abp.Modules; using Castle.Windsor; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; using System.Web.Http.Controllers; using System.Web.Http.Dispatcher;

namespace ReadyCare.Owin.WebApi.Host { public class WindsorCompositionRoot : AbpModule, IHttpControllerActivator { //private readonly IWindsorContainer container;

    public WindsorCompositionRoot()
    //public WindsorCompositionRoot(IWindsorContainer container)
    {
        //this.container = container;
    }

    public IHttpController Create(
        HttpRequestMessage request,
        HttpControllerDescriptor controllerDescriptor,
        Type controllerType)
    {
        var controller =
            (IHttpController)this.IocManager.IocContainer.Resolve(controllerType);

        request.RegisterForDispose(
            new Release(
                () => this.IocManager.IocContainer.Release(controller)));

        return controller;
    }

    private class Release : IDisposable
    {
        private readonly Action release;

        public Release(Action release)
        {
            this.release = release;
        }

        public void Dispose()
        {
            this.release();
        }
    }
}

}

And the startup is now

using Abp; using Abp.Modules; using Abp.WebApi.Configuration; // Add the following usings: using Owin; using ReadyCare.WebApi; using System.Web.Http; using System.Web.Http.Dispatcher;

namespace ReadyCare.Owin.WebApi.Host { [DependsOn(typeof(ReadyCareWebApiModule))] public class Startup : AbpModule { // This method is required by Katana: public new void Configuration(IAppBuilder app) { AbpBootstrapper bootstrapper = new AbpBootstrapper();

        bootstrapper.Initialize();

        GlobalConfiguration.Configuration.Services.Replace(
            typeof(IHttpControllerActivator),
        new WindsorCompositionRoot());

        var httpConfiguration = IocManager.Resolve<IAbpWebApiModuleConfiguration>().HttpConfiguration;

        //httpConfiguration.DependencyResolver = windsorDependencyResolver;

        // Use the extension method provided by the WebApi.Owin library:
        app.UseWebApi(httpConfiguration);
    }
}

}

But I get a "Object reference not set to an instance of an object." when the startup is called in the main

using Abp.Modules; using ReadyCare.WebApi; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Owin.Hosting;

namespace ReadyCare.Owin.WebApi.Host {

class Program
{
    static void Main(string[] args)
    {
        string baseUri = "http://localhost:8080";

        Console.WriteLine("Starting web Server...");
        try
        { 
        WebApp.Start<Startup>(baseUri);
        }
        catch(Exception ex)
        {
            string msg = ex.GetBaseException().Message;
        }
        
        Console.WriteLine("Server running at {0} - press Enter to quit. ", baseUri);
        Console.ReadLine();
    }
}

}

Note that my ReadyCareWebApiModule is intialising fine. like this

using System.Reflection; using Abp.Application.Services; using Abp.Modules; using Abp.WebApi; using Abp.WebApi.Controllers.Dynamic.Builders; using ReadyCare.Application; using ReadCare.ViewModels;

namespace ReadyCare.WebApi { [DependsOn(typeof(AbpWebApiModule), typeof(ReadyCareApplicationModule))] public class ReadyCareWebApiModule : AbpModule { public override void Initialize() { IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

        DynamicApiControllerBuilder
                   .For<IImageApplicationService<PatientBodyImageViewModel>>("telstra/readycare/ImageApplicationService")
                   .WithConventionalVerbs()
                   .Build();
        //DynamicApiControllerBuilder
        //    .ForAll<IApplicationService>(typeof(ReadyCareApplicationModule).Assembly, "telstra/readycare")
        //    .WithConventionalVerbs()
        //    .Build();

       

    }
}

}

Where I am using a generic for the ImageApplicationService as the DTOs are viewmodels for Xamarin/WPF and simple dtos for Web apps.

Answer

Sorry mate it was late last night! The problem was that I had not selected a target framework of net 4.5.1. Nuget really should say which framework is targeted and it would be really nice if the package info informed you that there were other releases available for other target frameworks! I guess this should be in your doco if you don't have it.

Best Regards, Alistair

Awesome thanks mate. I just found the problem by turning on breaking when the exceptions are thrown, after the usual plithora of useless exceptinns .net asp mvc creates mine came up that I was missing a config setting so one of my assemblies could not be loaded.

Wow thats interesting about Durandal, so will you be doing templates for this new framework? I guess you are just using Angular but I am not really a fan.

Best Regards, Alistair

Awesome yes thanks mate Automapper is the problem! I am using ignore for the mobile applications as I thought that was safer coding,

However even when I change automapper to map from the input, which has the correct loaded values (not new values), it still wants to add them. So I just put a work around for now till I can find whats wrong to clear the collection before I add the specified child values in.

Mapper.CreateMap<AddEndUserInput, EndUser>() .ForMember(x => x.Id, option => option.Ignore()) .ForMember(x => x.Patients, option => option.Ignore()) .ForMember(x => x.MobileApplications, option => option.Ignore()); //.ForMember(dest => dest.MobileApplications, opt => opt.MapFrom(src => src.MobileApplications));

public async Task<long> PostNewEndUserAsync(AddEndUserInput input) { try { Logger.Debug("Adding a new end InviteUser async: " + input.Surname);

            EndUser newEndUser = Mapper.Map&lt;EndUser&gt;(input);

            newEndUser.EndUserSecurityQuestionCode = -1;
            newEndUser.AcceptedTermsAndConditions = input.AcceptedTermsAndConditions;

            //// dummy code to get the mobile apps
            //    GetApplicationsInput getApplicationsInput = new GetApplicationsInput() { Name = null };
            //    var result = await _mobileApplicationRepository.GetMobileApplicationAsync&lt;MobileApplicationDto&gt;(getApplicationsInput);

            //    //var mobileApp = result.MobileApplications[0];

            //    input.MobileApplications = result.MobileApplications;

            if (input.MobileApplications == null)
            {
                // Add the mobile app

                if (String.IsNullOrEmpty(input.ApplicationName))
                {
                    // if none is specified use the DefaultRegistrationApplicationName 
                    input.ApplicationName = ConfigurationFacade.DefaultRegistrationApplicationName;
                }
                List&lt;MobileApplication&gt; mobileApplications = _mobileApplicationRepository.GetAllList(x => x.Name == input.ApplicationName);

                MobileApplication mobileApplication = mobileApplications.FirstOrDefault();

                if (mobileApplication == null)
                {
                    throw new Exception(String.Format("Mobile application {0} was not found to register the end user for.", input.ApplicationName));
                }

                newEndUser.MobileApplications.Add(_mobileApplicationRepository.Load(mobileApplication.Id));
            }
            else
            {
                **if (newEndUser.MobileApplications != null)
                {
                    newEndUser.MobileApplications.Clear();
                }**
                foreach (MobileApplicationDto mobileApplication in input.MobileApplications)
                {
                    newEndUser.MobileApplications.Add(_mobileApplicationRepository.Load(mobileApplication.Id));
                }
            }
            long id = await _endUserRepository.InsertAndGetIdAsync(newEndUser);
            return (id);
        }
        catch (Exception ex)
        {
            string msg = ex.GetBaseException().Message;
            UserFriendlyException userFriendlyException = new UserFriendlyException(msg);
            throw userFriendlyException;
        }            
    }
Answer

Thats great about returning the DTO I forgot about that!

And also your code is much simpler.

I didn't want to use an automapper for the map from the DTO to the domain object so I was using a function as not all the fields would be set in this update case but you don't need to with your solution.

Awesome thank you!

Sorry mate I forgot to check that it just didn't come u[ when I ran this.

PM> Get-Package -ListAvailable -Filter Abp -AllVersions

Id Version Description/Release Notes


Abp 0.8.2.0 ASP.NET Boilerplate core package.
Abp.Application 0.3.2.0 IMPORTANT: This package is not used anymore. Use <a class="postlink" href="https://www.nuget.org..">https://www.nuget.org..</a>. Abp.AutoMapper 0.8.2.0 AutoMapper integration package for ASP.NET Boilerplate.
Abp.EntityFramework 0.8.2.0 EntityFramework integration package for ASP.NET Boilerplate.
Abp.FluentMigrator 0.8.2.0 FluentMigrator package for ASP.NET Boilerplate
Abp.HangFire 0.8.2.0 HangFire integration package for ASP.NET Boilerplate.
Abp.Infrastructure.EntityFr... 0.3.2.0 IMPORTANT: This package is not used anymore. Use <a class="postlink" href="https://www.nuget.org..">https://www.nuget.org..</a>. Abp.Infrastructure.NHibernate 0.3.2.0 IMPORTANT: This package is not used anymore. Use <a class="postlink" href="https://www.nuget.org..">https://www.nuget.org..</a>. Abp.Modules.Core 0.3.2.0 ASP.NET Boilerplate - Core Module
Abp.Modules.Core.Application 0.3.2.0 ASP.NET Boilerplate - Core Module - Application Layer
Abp.Modules.Core.Infrastruc... 0.3.2.0 ASP.NET Boilerplate - Core Module - Infrastructure - EntityFramework
Abp.Modules.Core.Infrastruc... 0.3.2.0 ASP.NET Boilerplate - Core Module - Infrastructure - NHibernate
Abp.Modules.Core.Web 0.3.2.0 ASP.NET Boilerplate - Core Module - Web Layer
Abp.Modules.Core.Web.Api 0.3.2.0 ASP.NET Boilerplate - Core Module - Web Api Layer
Abp.Modules.Core.Web.Mvc 0.3.2.0 ASP.NET Boilerplate - Core Module - MVC
Abp.NHibernate 0.8.2.0 NHibernate integration package for ASP.NET Boilerplate.
Abp.Owin 0.8.2.0 OWIN integration package for ASP.NET Boilerplate.
Abp.RedisCache 0.8.2.0 Redis Cache integration package for ASP.NET Boilerplate
Abp.Samples.Blog.Application 0.3.0.2 A sample blog module for ASP.NET Boilerplate.
Abp.Samples.Blog.Core 0.3.0.2 A sample blog module for ASP.NET Boilerplate.
Abp.Samples.Blog.EntityFram... 0.3.0.2 A sample blog module for ASP.NET Boilerplate.
Abp.Samples.Blog.Web 0.3.0.2 A sample blog module for ASP.NET Boilerplate.
Abp.TestBase 0.8.2.0 ASP.NET Boilerplate test base. Used to build unit/integration tests fo... Abp.Web 0.8.2.0 Web package for ASP.NET Boilerplate.
Abp.Web.Api 0.8.2.0 ASP.NET Web API integration package for ASP.NET Boilerplate.
Abp.Web.Api.OData 0.8.2.0 ASP.NET Web API - OData integration package for ASP.NET Boilerplate.
Abp.Web.Mvc 0.8.2.0 ASP.NET MVC integration package for ASP.NET Boilerplate.
Abp.Web.Resources 0.8.2.0 This package contains resources (xml, js and css files) needed for ASP... Abp.Web.SignalR 0.8.2.0 SignalR integration package for ASP.NET Boilerplate.
Abp.Zero 0.8.2.0 ASP.NET Boilerplate - Module Zero. Implements tenant, role, user and s... Abp.Zero.EntityFramework 0.8.2.0 ASP.NET Boilerplate - Module Zero - EntityFramework.
Abp.Zero.Ldap 0.8.2.0 ASP.NET Boilerplate - Module Zero - LDAP (Active Directory) Integration. Abp.Zero.NHibernate 0.8.2.0 ASP.NET Boilerplate - Module Zero - NHibernate Integration.
OneWork.AbpApplication 1.0.0.1 Description
OneWork.AbpWebMvc 1.0.0.2 Description

Sorry the problem was that I was not getting the nuget restore to work properly in Visual Studio Team Services. If the packages folder is present OR Even if you have one pending to checkin (i.e not actually checked in) then nuget restore will not restore. And you should not have a Nuget.Targets file and packages.config in your .nuget folder.

I updated all of my projects to .net 4.6.1 and updated all packages to the latest code and its all working really great, thanks very much!!

Perhaps I could do an upgrade to EF7 it has support for InMemory databases with a nuget package and allows configuration of which type to use.

Sorry for the delay on this.

When I try a GET on <a class="postlink" href="http://localhost:6634/api/services/app/flight/getTest1">http://localhost:6634/api/services/app/flight/getTest1</a>

I get No HTTP resource was found that matches the request URI 'http://localhost:6634/api/services/app/flight/getTest1'

And the same for my PUT 'http://localhost:6634/api/services/app/flight/GetFlightsAsync'." "message": "No HTTP resource was found that matches the request URI

And the dynamic controller in the WebAPI module is built like this DynamicApiControllerBuilder .ForAll<IApplicationService>(typeof(DailyFlightsApplicationModule).Assembly, "app") .Build(); Best Regards, Alistair

Showing 1 to 10 of 20 entries