Base solution for your next web application

Activities of "gpcaretti"

And so? Do we have the solution? Also I'd like to have a login via Angular.

At the moment I have the home page working anonymous (I achieved it with a small fix. see <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/pull/57">https://github.com/aspnetboilerplate/mo ... te/pull/57</a>) and now I'd like to a add a popup window for login via Angular WebApi

In EF, database commits are normally visible only at the end of the transaction or once you call the commit() method or scope.complete() method.

If you take a look to the Abp Unit of Works source code you see:

protected override void CompleteUow()
        {
            SaveChanges();
            if (CurrentTransaction != null)
            {
                CurrentTransaction.Complete();
            }
            DisposeUow();
        }

        protected override async Task CompleteUowAsync()
        {
            await SaveChangesAsync();
            if (CurrentTransaction != null)
            {
                CurrentTransaction.Complete();
            }
            DisposeUow();
        }

It follows the same approach of teh EF.

So, to close, these are the main reasons you don't see your changes in the DB.

I suggest you two approaches:

  1. Play with the DB isolationLevel so that you can read dirty data.
  2. More clean: Use the Abp events. Register a method to the Committed event , Call SaveChangesAsync, that exit from your event. In this way the Commit Event will be fired for your post-commit operations.

Further info here: <a class="postlink" href="https://msdn.microsoft.com/en-us/data/dn456843.aspx">https://msdn.microsoft.com/en-us/data/dn456843.aspx</a>

For the first question, see: <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/pull/57">https://github.com/aspnetboilerplate/mo ... te/pull/57</a>

You have to remove the attribute

[AutoMapFrom(typeof(Article))]

and create your own map.

From Abp v. 1.0.0 this can be done in Abp MVC and SPA template in the "Application" project. See YourProjectApplicationModule.cs. There you can find something like:

public override void PreInitialize()
        {
            Configuration.Modules.AbpAutoMapper().Configurators.Add(mapper =>
            {
                //Add your custom AutoMapper mappings here...
                //mapper.CreateMap<,>()
               ...
            });
        }

Gp

See: <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/issues/56">https://github.com/aspnetboilerplate/mo ... /issues/56</a>

And: <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/pull/57">https://github.com/aspnetboilerplate/mo ... te/pull/57</a>

Answer

Hi All, I have the same problem. Anyone solved the issue?

<cite>Shyamjith: </cite> I did wrote code here but i can't invoke it using Repository

What do you mean with this sentence? Do you mean you don't see methods from a client class of your repository? If so, it is a matter of interfaces.

Your concrete repository is probably declare in this way:

public class MySpecificRepo : SampleRepositoryBase<MyEntity, int>, IMySpecificRepo {
   ...
}

This means, clients see your class by the interface IMySpecificRepo.

So you have to define a ISampleRepositoryBase interface declaring the new methods added to SampleRepositoryBase and declare your Concrete Interface by extending it:

public interface ISampleRepositoryBase<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey> {
   // here your additional common methods declarations
  ...
}

 public interface IMySpecificRepo :  ISampleRepositoryBase<MyEntity, int> {
   // here your specific repository methods
   ...
}

public class MySpecificRepo : SampleRepositoryBase<MyEntity, int>, IMySpecificRepo {
   // here the implementations
   ...
}

In this way all works

Gp

Answer

<cite>hikalkan: </cite> this maybe related to that: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1163">https://github.com/aspnetboilerplate/as ... ssues/1163</a> After v0.10 release, please try it again.

It is still there, but I went on with my investigation and I was able to get the exception thrown when running the code:

await UsingDbContextAsync(AbpSession.TenantId, async context => {
        entity = await context.REProperties.OfType<PropertyForSale>()
            .FirstAsync(u => (u.TenantId == AbpSession.TenantId));
    });

I receive this error:

Result StackTrace:	
at Effort.DbConnectionFactory.CreateTransient()
   at MyNewHouse.Tests.MyNewHouseTestBase.UseSingleDatabase() in C:\WA\GpES\MyNewHouse\Tests\MyNewHouse.Tests\MyNewHouseTestBase.cs:line 68
   at MyNewHouse.Tests.MyNewHouseTestBase.PreInitialize() in C:\WA\GpES\MyNewHouse\Tests\MyNewHouse.Tests\MyNewHouseTestBase.cs:line 60
   at Abp.TestBase.AbpIntegratedTestBase`1.InitializeAbp() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.TestBase\TestBase\AbpIntegratedTestBase.cs:line 42
   at Abp.TestBase.AbpIntegratedTestBase`1..ctor(Boolean initializeAbp) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.TestBase\TestBase\AbpIntegratedTestBase.cs:line 34
   at Abp.TestBase.AbpIntegratedTestBase`1..ctor(Boolean initializeAbp) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.TestBase\TestBase\AbpIntegratedTestBase.cs:line 34
   at MyNewHouse.Tests.MyNewHouseTestBase..ctor() in C:\WA\GpES\MyNewHouse\Tests\MyNewHouse.Tests\MyNewHouseTestBase.cs:line 27
   at MyNewHouse.Tests.Locations.CityAppService_Tests..ctor() in C:\WA\GpES\MyNewHouse\Tests\MyNewHouse.Tests\Locations\CityAppService_Tests.cs:line 24
   at MyNewHouse.Tests.Auctions.AuctionAppService_Tests..ctor() in C:\WA\GpES\MyNewHouse\Tests\MyNewHouse.Tests\Auctions\AuctionAppService_Tests.cs:line 22
----- Inner Stack Trace -----
   at Effort.Provider.EffortProviderConfiguration.RegisterDbConfigurationEventHandler()
   at Effort.Provider.EffortProviderConfiguration.RegisterProvider()
   at Effort.DbConnectionFactory..cctor()
----- Inner Stack Trace -----
   at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.AddLoadedHandler(EventHandler`1 handler)
   at System.Data.Entity.DbConfiguration.add_Loaded(EventHandler`1 value)
   at Effort.Provider.EffortProviderConfiguration.RegisterDbConfigurationEventHandler()
Result Message:	
System.TypeInitializationException : The type initializer for 'Effort.DbConnectionFactory' threw an exception.
---- Effort.Exceptions.EffortException : The Effort library failed to register its provider automatically, so manual registration is required.

a) Call the Effort.Provider.EffortProviderConfiguration.RegisterProvider() method at entry point of the application

or

b) Add the following configuration to the App.config file:
   &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
         &lt;add name=&quot;Effort.Provider&quot;
              invariant=&quot;Effort.Provider&quot;
              description=&quot;Effort.Provider&quot;
              type=&quot;Effort.Provider.EffortProviderFactory, Effort&quot; /&gt;
      &lt;/DbProviderFactories&gt;
   &lt;/system.data&gt;


   &lt;entityFramework&gt;
      &lt;providers&gt;
         &lt;provider invariantName=&quot;Effort.Provider&quot;
                   type=&quot;Effort.Provider.EffortProviderServices, Effort&quot; /&gt;
      &lt;/providers&gt;
   &lt;/entityFramework&gt;
-------- System.InvalidOperationException : The Entity Framework was already using a DbConfiguration instance before an attempt was made to add an 'Loaded' event handler. 'Loaded' event handlers can only be added as part of application start up before the Entity Framework is used. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information.

I hope I helped you. Gp

Answer

Going further to this point, I got the exception received on my unit test.

When I run this code:

[Fact]
public async Task GetPropertyFull_Test() {
    PropertyForSale entity = null;
    await UsingDbContextAsync(AbpSession.TenantId, async context => {
        entity = await context.REProperties.OfType<PropertyForSale>()
            .FirstAsync(u => (u.TenantId == AbpSession.TenantId));
    });
   . . .
}

The exception I receive when fetching the entity is:

System.TypeInitializationException : The type initializer for 'Effort.DbConnectionFactory' threw an exception.
---- Effort.Exceptions.EffortException : The Effort library failed to register its provider automatically, so manual registration is required.

a) Call the Effort.Provider.EffortProviderConfiguration.RegisterProvider() method at entry point of the application

or

b) Add the following configuration to the App.config file:
   <system.data>
      <DbProviderFactories>
         <add name="Effort.Provider"
              invariant="Effort.Provider"
              description="Effort.Provider"
              type="Effort.Provider.EffortProviderFactory, Effort" />
      </DbProviderFactories>
   </system.data>

   <entityFramework>
      <providers>
         <provider invariantName="Effort.Provider"
                   type="Effort.Provider.EffortProviderServices, Effort" />
      </providers>
   </entityFramework>

But If I add this line of code (theoretically not neede) at the beginning of the code, all works:

[Fact]
public async Task GetPropertyFull_Test() {
     var dummyService = Resolve<IUserAppService>();  // why?

    PropertyForSale entity = null;
    await UsingDbContextAsync(AbpSession.TenantId, async context => {
    ...
}

Anybody can help me?

Tnx, gp

Answer

Thanks again for your reply. I went on with tests and I think it might be a bug somewhere (in your code?) as I found a workaround to solve the issue:

if I ran the same test by calling first a _userAppService.FindUser(...), everything works! See my working new testing code:

[Fact]
public async Task GetPropertyFull_Test() {
    PropertyForSale entity = null;
    await UsingDbContextAsync(AbpSession.TenantId, async context => {
        entity = await context.REProperties.OfType<PropertyForSale>()
            .FirstAsync(u => (u.TenantId == AbpSession.TenantId));
    });
    // only needed for a possible bug!
    await _userAppService.FindUser(long.MaxValue); // only needed for a possible bug!

    // test
    var output = await _pfsAppService.GetPropertyFull(entity.Id);
    output.ShouldNotBeNull();
    output.Id.ShouldBe(entity.Id);
}

This test works! But if I comment out code lines related to user, specifically the line:

var userDto = await _userAppService.FindUser(long.MaxValue); // only needed for a possible bug!

the test fails.

The test works even if I move the 'finduser' code in the Test's constructor leaving my test method clean:

public PfsAppService_Tests() {
    _pfsAppService = Resolve<IPfsAppService>();

    // only needed for a possible bug!
    _userAppService = Resolve<IUserAppService>();
    _userAppService.FindUser(long.MaxValue);
}

[Fact]
public async Task GetPropertyFull_Test() {
    PropertyForSale entity = null;
    await UsingDbContextAsync(AbpSession.TenantId, async context => {
        entity = await context.REProperties.OfType<PropertyForSale>()
            .FirstAsync(u => (u.TenantId == AbpSession.TenantId));
    });

    // test
    var output = await _pfsAppService.GetPropertyFull(entity.Id);
    output.ShouldNotBeNull();
    output.Id.ShouldBe(entity.Id);
}

What I miss?

Showing 11 to 20 of 23 entries