Base solution for your next web application

Activities of "winson"

for example, I have an IAbcAppService and AppService class, but how can I call it in my controller? I don't know how to instantiate it

in my app service:

public class ABCAppService: IABCAppService
{
        private readonly IRepository<ABCModel> _abcRepository;

        public ABCAppService(IRepository<ABCModel> abcRepository)
        {
            _abcRepository = abcRepository;
        }
}

and in my controller:

public class ABCController : ABCControllerBase
{
        private readonly IABCAppService _abcAppService;

        public ABCController()
        {
        	//should I use this way? but it doesn't work :(
            _abcAppService = IocManager.Instance.Resolve<IABCAppService>();
        }
}

just don't know how to init the _abcAppService in controller.

I want to create the multiple pages project and not use angular script, so I want to call the app service directly in my controller, but I tried many ways and still failed, after I read the Dependency Injection , seems there is a way to resolve the service directly, but I still failed, below is my code:

app service:

private readonly IFormBuilderRepository _formBuilderRepository;

        public FormBuilderAppService(IFormBuilderRepository formBuilderRepository)
        {
            _formBuilderRepository = formBuilderRepository;
        }

in controller:

private readonly IIocResolver _iocResolver;

        public FormBuilderController(IIocResolver iocResolver)
        {
            _iocResolver = iocResolver;
        }

and in the action:

[HttpPost]
        [UnitOfWork]
        public JsonResult Index(FormBuilderInput formBuilder)
        {
            var _formBuilderAppService = _iocResolver.Resolve<IFormBuilderAppService>();
            _formBuilderAppService.Create(formBuilder);
            _iocResolver.Release(_formBuilderAppService);

            return Json(new { Name = formBuilder.Name });
        }

after run these code, I got the below error:

ABP The entity type FormBuilderModel is not part of the model for the current context.

I have no ideas :(

ok, I have resolved my problem, it's spend me a whole day, it maybe because my entity model name is not same with the database table name, when I drop the table and run update-database again, the problem is solved :(

yes, actually I tried everything before, but still not working, but when I reset the DB and run update-database again, that's working, maybe I use the difference table name between entity and database, but suppose that's not be an issue, I have set the table attribute in the entity model

Yes, that strange, when I create a new table and controller, I got the error again, don't know why :(

I got the below errors:

Server Error in '/' Application.

Can't create component 'MPeLife.FormLayoutApp.FormLayoutAppService' as it has dependencies to be satisfied.

'MPeLife.FormLayoutApp.FormLayoutAppService' is waiting for the following dependencies:
- Service 'Abp.Domain.Repositories.IRepository`1[[MPeLife.Models.FormLayout, MPeLife.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.

in my controller:

private readonly IFormLayoutAppService _formLayoutAppService;

public FormLayoutController(IFormLayoutAppService formLayoutAppService)
{
       _formLayoutAppService = formLayoutAppService;
}

in app service:

private readonly IRepository&lt;FormLayout&gt; _formLayoutRepository;

public FormLayoutAppService(IRepository&lt;FormLayout&gt; formLayoutRepository)
{
     _formLayoutRepository = formLayoutRepository;
}

I didn't change any things, just create the new table:(

I found that if I use a repository to inject the app service, and it's working:

private readonly IFormLayoutRepository _formLayoutRepository;

        public FormLayoutAppService(IFormLayoutRepository formLayoutRepository)
        {
            _formLayoutRepository = formLayoutRepository;
        }

but why it must be use Repository? I have no other custom method to use, so if I create the Repository for each table, these Repositories are empty, and I have to create an interface and implements it, but I just want to use the simple generic methods:

IRepository<MyModel>

I inherit IModificationAudited and ICreationAudited interface and create CreatorUserId and LastModifierUserId fields, but when I insert a record, I have set the value to these fields like below:

var item = new Item
{
    Active = true,
    Name = input.Name,
    Value = input.Value,
    CreationTime = DateTime.Now,
    LastModificationTime = DateTime.Now,
    CreatorUserId = 1, //TODO: for testing
    LastModifierUserId = 1
};

_itemRepository.Insert(item);

but this just can save the LastModifierUserId value, and the CreatorUserId is null, if the LastModifierUserId is null, when I do the update, I also can't update it:

var item = _itemRepository.Get(input.Id);
            
item.Name = input.Name;
item.Value = input.Value;
item.LastModificationTime = DateTime.Now;
item.LastModifierUserId = 1; //TODO: for testing

_itemRepository.Update(item);

after that, the LastModifierUserId is also null.

I have created the ForeignKey for these fields :

public long? LastModifierUserId { get; set; }

public long? CreatorUserId { get; set; }

[ForeignKey("CreatorUserId")]
public virtual AdminUser CreatorUser { get; set; }

[ForeignKey("LastModifierUserId")]
public virtual AdminUser LastModifierUser { get; set; }

Yes, after I used the Repository and it's working, below is my entity, there is no any especially:

public class FormLayout : Entity, IModificationAudited, ICreationAudited
{
    public virtual bool Active { get; set; }

    [Required]
    public virtual int CateTabId { get; set; }

    [Required]
    public virtual string Name { get; set; }

    [Required]
    public virtual string Value { get; set; }

    public DateTime CreationTime { get; set; }        

    public DateTime? LastModificationTime { get; set; }

    public long? LastModifierUserId { get; set; }

    public long? CreatorUserId { get; set; }

    [ForeignKey("CreatorUserId")]
    public virtual AdminUser CreatorUser { get; set; }

    [ForeignKey("LastModifierUserId")]
    public virtual AdminUser LastModifierUser { get; set; }

    [ForeignKey("CateTabId")]
    public virtual CategoryTab CateTab { get; set; }
}

I have my own user table, just want to use the ABP Authorization feature and session, but don't want to implement the module-zero project, can I do that?

thanks!

anyone can help?

thanks!!!!

Showing 1 to 10 of 25 entries