Open Closed

How to access entities from public website #1423


User avatar
0
cbogner85 created

Hello,

I'm currently developing a webshop. Therefore I thought of having the product list and order process in public website, while admin tasks should be in the backend interface.

My problem is that I can't get access to the entities from web public. I noticed that I can inject e.g. the IProductAppService in Controllers, however, I can't access JavaScript API Controllers. Something like

var productService = window.myWebShop.products.products;
...

doesn't work (of course in backend app it works).

Additionally, I use DevExtreme for ASP.net Core and here I also can't access API Controllers (since the backend has a different port, it creates a wrong Controller URL). So, this:

Html.DevExtreme().DataGrid<Product>()
            .DataSource(d => d.Mvc()
                .Controller("Product") // Application Service Name without 'AppService'
                .LoadAction("GetList") // Method Name without 'Async'
                .Key("id")
            )

doesn't work, too.

I also tried to set RemoteServices of public website's appsettings.json to the location of the backend, but it didn't work either:

  "RemoteServices": {
    "Default": {
      "BaseUrl": "https://localhost:44309"
    }
  },

Could you please point me into the right direction? I think I might have to register AbpServiceProxies somewhere?

Thanks and best regards Claus


4 Answer(s)
  • User Avatar
    0
    davidc@educlarity.com created

    Hi there; Sorry I don't have an answer to your question. But Im also a DevExtreme user and have found it difficult to integrate DevExtreme with ABP.IO (and aspnetzero).

    Do you have problems with the .Key("id") part? i've found that since ABP uses inherited ID numbers, DevExtreme has a hard time finding the ID. i've had limited success working with the JSON configuration (camel case vs pascal case).

    Sorry, didn't mean to hijack your post, Im looking forward to their response as well.

    Best, --Dave

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Are you using tiered architecture? if not, you just need configure auto api controllers for public project.

    private void ConfigureAutoApiControllers()
    {
        Configure<AbpAspNetCoreMvcOptions>(options =>
        {
            options.ConventionalControllers.Create(typeof(MyProjectNameApplicationModule).Assembly);
        });
    }
    

    If you are using tiered architecture, you can create a controller to call appservice, e.g:

    public class ProductController : MyProjectNameController
    {
        private readonly IProductAppService _productAppService;
    
        public ProductController(IProductAppService productAppService)
        {
            _productAppService = productAppService;
        }
    
        public async Task<IActionResult> GetListAsync()
        {
            return Json(await _productAppService.GetListAsync())
        }
    }
    
  • User Avatar
    0
    cbogner85 created

    Hi liangshiwei,

    I'm using non tiered architecture.

    Therefore, this snippet:

    private void ConfigureAutoApiControllers() 
    { 
        Configure<AbpAspNetCoreMvcOptions>(options => 
        { 
            options.ConventionalControllers.Create(typeof(MyProjectNameApplicationModule).Assembly); 
        }); 
    } 
    

    worked like a charm, thank you! I was hoping for such a simple solution but couldn't find it myself :-) Thanks!

  • User Avatar
    0
    cbogner85 created

    Hi there; Sorry I don't have an answer to your question. But Im also a DevExtreme user and have found it difficult to integrate DevExtreme with ABP.IO (and aspnetzero).

    Do you have problems with the .Key("id") part? i've found that since ABP uses inherited ID numbers, DevExtreme has a hard time finding the ID. i've had limited success working with the JSON configuration (camel case vs pascal case).

    Sorry, didn't mean to hijack your post, Im looking forward to their response as well.

    Best, --Dave

    Hi Dave,

    No problem :-)

    With ASP.NET Zero, I used DevExtreme jQuery version instead of the HTML wrappers as suggested by ABP developers. It worked great, however I couldn't use benefits of the wrappers such as syntax highlighting etc.

    With abp.io Commercial I started to use DevExtreme ASP.NET Core Controls/ wrappers as described in the following community article: Using DevExtreme Components with the ABP Framework.

    I think the most important part is to create specific AppService methods for DevExtreme. E.g. I create a GetDxListAsync method that mirrors standard GetListAsync behaviour but uses DataSourceLoadOptions as input paramter and returns LoadResult instead of PagedResultDto. If you use standard ABP methods, it works as well, however DevExtreme pagers won't work and you'd have to use nested json field names, e.g. items.id as id parameter.

    Regarding PascalCase/ camelCase: The community article suggests to use JsonProperty attributes to change ABP's behaviour of converting names to camelCase. I don't do this as I prefer camelCase in json objects. If you don't set JsonProperty, you can just use id or productName as field names (as in my snippet above) instead of Id or ProductName. However, if you want to use columns.AddFor(m => m.ProductName); it won't work with pascalCase. Therefore I created an extension method AddCamelCaseFor as suggested by DevExpress Support (How to enable camel case for DevExtreme MVC Controls / MVC Controls - How to allow CamelCase for AddFor methods.

    Let me know if I can assist further.

    Best Claus

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11