Base solution for your next web application

Activities of "bvz"

When I posted the question, I could not make the error go away. (The error said something about the context being disposed, or something along those lines.)

Now, when trying to set up the same scenario so that I can post code examples... it just works. I cannot get reproduce the error.

Works perfectly, the UOW is used across all three layers. I don't know what I was doing wrong when I posted the original question.

Thank you for your time and effort anyway! I really appreciate all the effort you put into this great framework.

Currently, if I create a class that implements IApplicationService, or EfRepositoryBase, a UnitOfWork is created automatically. So if my ApplicationService gets a repository injected directly, the UnitOfWork created in the application service is used in the repository as well.

I want to create a layer between the repository and application service, called the manager layer.

But if I inject like this:

repository -> manager -> application service,

Repository is no longer injected into application service directly, and unit of work does not reach the repository through the manager.

So my question is, how can I get my manager to use the unit of work created in the application service, so that it is in turn used in the repository injected into the manager as well?

Putting [UnitOfWork] on the method inside the manager does the trick, as well as doing this: using (var uow = _unitOfWorkManager.Begin())

But I dont have to do this on every repository or application service method, so how can I achieve the same thing in the manager so that the same unit of work is shared across all three layers?

Thank you.

I am writing unit tests for Abp, and I have a class that inherits from Abp.TestBase.AbpIntegratedTestBase.

When I run this code:

var current = LocalIocManager.IocContainer.Resolve<IAbpSession>();

It resolves to a session of type:

Abp.TestBase.Runtime.Session.TestAbpSession

I did not register this in Castle, so I am guessing that AbpIntegratedTestBase is doing this registration. How can I override this with my own session for testing purposes, so that I can set the logged in user Id for testing?

Thank you for your time and effort!

Question

Normally, in an ASP.Net application, I would override Application_Error in Global.asax.cs.

However, when I throw an exception in one of my BaseApplicationService implementations to test:

throw new Exception("TEST!!!");

the code in Global.asax.cs is never hit.

So I now have the following:

public override void Initialize()
        {
            AutoMapperConfig.Configure();
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

            EventBus.Default.Register<AbpHandledExceptionData>(x => HandleException(x.Exception));
        }

        private void HandleException(Exception ex)
        {
            EntException exObj = ex.GetHttpExceptionObject();
        }

This works. However, I need the HttpRequest object, becuase I need to log Headers and Form values and UserAgents and all kinds of other goodies from the HttpRequest object. This is easy in the Global.asax.cs Application_Error, because HttpRequest is in scope there.

So I need to:

  1. Access the Request object where the exception was raised.
  2. Make sure exceptions handled by Asp.Net boilerplate internals still reach Global.asax.cs.

Please advise. Thank you for your time and effort.

I am trying to use the ICreationAudited interface on the Entities.

The problem I am running into is that the tables I am mapping to use int as the column type, not long.

The error is:

The 'CreatorUserId' property on 'EntUser' could not be set to a 'System.Int32' value. You must set this property to a non-null value of type 'System.Int64'.

So I understand why this is happening, my question is if it is possible to overcome this problem?

I have reat the Unit Of Work documentation page, however, I have a question.

Consider this code:

public EntUserUnit AddUserUnit(EntUserUnit userUnit)
        {            
            Context.UserUnits.Add(userUnit);
            return userUnit;
        }

        public List<EntUserUnit> AddUserUnits(List<EntUserUnit> userUnits)
        {
            return userUnits.Select(AddUserUnit).ToList();
        }

This code is in an Application Service. The documentation states that a transaction will be started when I call theAddUserUnits(List<EntUserUnit> userUnits) method. This method then repeatedly calls another method, also on the Application Service.

If I send a list with 10 objects, will they all be added in the same transaction? If any one of them fails, will they all be rolled back?

What is the best way that you would recoment calling stored procedures through the EntityFramework provider?

Currently I have added the following to the DbContext file:

public virtual int? spr_AddUser(Nullable<int> clientID, string username, string password, string name, string surname, string iDNumber, string email, Nullable<int> createdBy)
        {
            var clientIdPar = new SqlParameter("@ClientID", clientID);

            var usernamePar = new SqlParameter("Username", username);

            var passwordPar = new SqlParameter("Password", password);

            var namePar = new SqlParameter("Name", name);

            var surnamePar = new SqlParameter("Surname", surname);

            var idNumberPar = new SqlParameter("IDNumber", iDNumber);

            var emailPar = new SqlParameter("Email", email);

            var createdByPar = new SqlParameter("CreatedBy", createdBy);

            var retvalPar = new SqlParameter("@retval", SqlDbType.Int);
            retvalPar.Direction = ParameterDirection.Output;
            
            var parameters = new object[] { clientIdPar, usernamePar, passwordPar, namePar, surnamePar, idNumberPar, emailPar, createdByPar, retvalPar };

            this.Database.ExecuteSqlCommand(
                "exec @retval = spr_AddUser @ClientID,@UserName,@Password,@Name,@Surname,@IDNumber,@Email,@CreatedBy",
                parameters);
            return (int) retvalPar.Value;
        }

This works,but I am not sure if this is the best way to call stored procedures when using ABP.

Could someone who is more experienced with ABP point me in the right direction?

POST works fine for now.

But how does it know how to make it GET and when to make it POST?

When the ApplicationService implementations are exposed as a REST service, how is determined if they should be POST, PUT or GET etc?

Can I override this somehoe? If I want updates to be PUT, and inserts to be POST, how do I tell ABP to expose them the way I want to when generating the REST api?

Thank you.

Thank you for your reply.

So internally, whenever ABP wants to find out who is logged in (to show the correct menu items, or to send the id to the PermissionChecker etc), it will always use the UserID from the IAbpSession implemtation, which it will grab from the IoC?

Showing 1 to 10 of 13 entries