Starts in:
2 DAYS
15 HRS
59 MIN
18 SEC
Starts in:
2 D
15 H
59 M
18 S

Activities of "hansmogren"

Thanks, that change made the trigger be registered and triggered.

However the dependency injection failed while instantiating my trigger class. I am injecting an IRepository into it and got an exception: System.InvalidOperationException: 'Unable to resolve service for type 'MyProjectName.IMyEntityRepository' while attempting to activate 'MyProjectName.BeforeSaveTrigger'.'

I solved this by including the line t.UseApplicationScopedServiceProviderAccessor(_ => context.Services.GetServiceProviderOrNull()); as below since the the documentation at https://github.com/koenbeuk/EntityFrameworkCore.Triggered/wiki/Dependency-injection mentions this solution:

Configure a method that returns the current relevant ServiceProvider. This can be done by providing a method through: triggerOptions.UseApplicationScopedServiceProviderAccessor(sp => ...). The first argument will be either the application ServiceProvider if available or otherwise the internal service provider.

Does this seem like a reasonable solution or will it break something?

            options.Configure(c =>
            {
                c.UseSqlServer();
                c.DbContextOptions.UseTriggers(t =>
                {
                    t.UseApplicationScopedServiceProviderAccessor(_ => context.Services.GetServiceProviderOrNull());
                    t.AddTrigger<BeforeSaveTrigger>();
                });
            });

hi @all

https://github.com/abpframework/abp/commit/b73f9e2c6e91251f800d5aa3a00b1edf516ed933

Thanks,

After trying this I get this error when running the unit test:

Volo.Abp.AbpInitializationException : An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module MyProject.MyProjectTestBaseModule, MyProject.TestBase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: SQLite Error 1: 'no such table: AbpSettings'.. See the inner exception for details.
---- Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: 'no such table: AbpSettings'.

And what about MyProjectNameEntityFrameworkCoreTestModule.CreateDatabaseAndGetConnection? Should it use the MyProjectNameMigrationsDbContext, not the new TestDbContext?

private static SqliteConnection CreateDatabaseAndGetConnection()
{
    var connection = new SqliteConnection("Data Source=:memory:");
    connection.Open();
    var options = new DbContextOptionsBuilder<MyProjectNameMigrationsDbContext>()
        .UseSqlite(connection)
        .Options;
    using (var context = new MyProjectNameMigrationsDbContext(options))
    {
        context.GetService<IRelationalDatabaseCreator>().CreateTables();
    }
    return connection;
}

I have a similar problem where I need to handle DateTimeOffset data and sqlite. I found this article. Where would I typically add the code? How do I create a separate DbContext for the unit tests? Today the tests use the MigrationsDbContext. I could edit the proper EntityFrameworkCore.DbContext and add code to the OnModelCreating and check if the the database is sqlite but that seems like the wrong way.

You can create a DbContext in the unit test to change DecimalProperty.

The Decimal type provides a high level of precision. If you don't need that level of precision, however, we recommend using double instead. You can use a value converter to continue using decimal in your classes.

modelBuilder.Entity<MyEntity>() 
.Property(e => e.DecimalProperty) 
.HasConversion<double>();****

Thank you! I've added the attribute [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] and now the response is 401 Unauthorized. May I ask if this attribute could have any other unwanted consequences?

Thanks! However, when I try that I get an error on application start:

An unhandled exception occurred while processing the request. InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, IDbContextOptions contextOptions, DbContext context)

Stack trace:

<br>

InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

    Microsoft.EntityFrameworkCore.Internal.DbContextServices.Initialize(IServiceProvider scopedProvider, IDbContextOptions contextOptions, DbContext context)
    Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
    Microsoft.EntityFrameworkCore.DbContext.get_ChangeTracker()
    Volo.Abp.EntityFrameworkCore.AbpDbContext<TDbContext>.Initialize(AbpEfCoreDbContextInitializationContext initializationContext)
    Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider<TDbContext>.CreateDbContextAsync(IUnitOfWork unitOfWork, string connectionStringName, string connectionString)
    Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider<TDbContext>.GetDbContextAsync()
    Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository<TDbContext, TEntity>.GetDbSetAsync()
    Volo.Abp.LanguageManagement.EntityFrameworkCore.EfCoreLanguageRepository.GetListAsync(bool isEnabled)
    Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous<TResult>(IInvocation invocation, IInvocationProceedInfo proceedInfo)
    Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue<TResult>.ProceedAsync()
    Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter<TInterceptor>.InterceptAsync<TResult>(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func<IInvocation, IInvocationProceedInfo, Task<TResult>> proceed)
    Volo.Abp.LanguageManagement.DatabaseLanguageProvider.oBPl0rvdv()
    Volo.Abp.Caching.DistributedCache<TCacheItem, TCacheKey>.GetOrAddAsync(TCacheKey key, Func<Task<TCacheItem>> factory, Func<DistributedCacheEntryOptions> optionsFactory, Nullable<bool> hideErrors, bool considerUow, CancellationToken token)
    Volo.Abp.LanguageManagement.DatabaseLanguageProvider.GetLanguagesAsync()
    Microsoft.AspNetCore.RequestLocalization.DefaultAbpRequestLocalizationOptionsProvider.GetLocalizationOptionsAsync()
    Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass6_1+<<UseMiddlewareInterface>b__1>d.MoveNext()
    Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Hi,

I'm sorry I haven't been able to get back to you with source. In the meantime I'd just like to clarify what I mean.

If I make a request to one of the built-in abp endpoints, e.g. get /api/lepton-theme-management/settings without a valid bearer token I get a 401 Unauthorized response with the body <br>

{
  "error": {
    "code": "Volo.Authorization:010001",
    "message": "Authorization failed! Given policy has not granted.",
    "details": null,
    "data": {},
    "validationErrors": null
  }
}

<br> However if I make a request to one of our custom controllers in the same way without a valid bearer token I get a 302 Found response with the Location header value https://localhost:44327/Account/Login?ReturnUrl=%2Fapi%2Ffoo%2Fbar instead.

What do I need to do to get a 401 Unauthorized response from our endpoints like the built-in abp endpoints?

I want to use https://github.com/koenbeuk/EntityFrameworkCore.Triggered in my ABP solution but I can't figure out how to register the triggers with my AbpDbContext.

This is what the documentation for EntityFrameworkCore.Triggered suggests:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddDbContext<ApplicationContext>(options => {
                options.UseTriggers(triggerOptions => {
                    triggerOptions.AddTrigger<MyTrigger>();
                });
            })
    }
}

How can I use this library with with ABP?

HI

can you share some code of your web api?

Sure, what parts would you like to see? Is there a private messaging feature on these boards?

CORS works but you need to add the production server addresses when you deploy. Also you need to configure IdentityServerClientRedirectUris db table (this is probably configured from the UI)

Thanks for answering. I've added the addresses in the "allowed cors origins" dialog, is there somewhere else they should go? What configuration needs to be done with the IdentityServerClientRedirectUris table?

Hi!

We use bearer / token authentication for a mobile app that communicates with our web api. As of now requests that do not contain a proper bearer token will get a response with http status code 302 and the location header with a value like https://example.com/Account/Login?ReturnUrl=/api/foo/bar. How can we change this behaviour and insted return a 401 “Unauthorized” response for requests that do not contain a proper bearer token?

  • ABP Framework version: v4.3.0
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:
Showing 11 to 20 of 25 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06