Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Interface triggers is call class method #198

Open
timeshift92 opened this issue Sep 15, 2022 · 1 comment
Open

Feature: Interface triggers is call class method #198

timeshift92 opened this issue Sep 15, 2022 · 1 comment

Comments

@timeshift92
Copy link

Describe the solution you'd like

i have add attributes in interface,

but i don't catch triggers in the advice

    [Advice(Kind.Around)]
    public object Handle(
            [Argument(Source.Target)] Func<object[], object> target,
            [Argument(Source.Name)] string methodName,
            [Argument(Source.Arguments)] object[] args,
            [Argument(Source.Triggers)] Attribute[] triggers
            )
    {

$code

public interface IPerson
{
    [Raise(Depend = $"People")]
    Person Create(string name, string fullName, string email);
    [Raise(Depend = nameof(Person.People), Type = RaiseType.UPDATE)]
    Person Update(Person _person);
    [Raise(Depend = nameof(Person.People), Type = RaiseType.DELETE)]
    public void Delete(Guid Id);
    [Cache]
    List<Person> People();
    [Cache]
    List<Person> People(int count);
    [Cache]
    List<Person> Test();
}

public class Person : IPerson
{
    private static List<Person> _People = new();
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string FullName { get; set; }
    public string Email { get; set; }

    public override int GetHashCode() => HashCode.Combine(Id, nameof(Person));



    public Person Create(string name, string fullName, string email)
    {
        var p = new Person()
        {
            Email = email,
            FullName = fullName,
            Name = name,
            Id = Guid.NewGuid()
        };
        _People.Add(p);

        return p;

    }


    public Person Update(Person _person)
    {
        for (int i = 0; i < _People.Count; i++)
        {
            if (_People[i].Id == _person.Id)
            {
                _People[i] = _person;
            }
        }


        return _person;

    }
    public void Delete(Guid Id)
    {
        var person = _People.Where(x => x.Id.Equals(Id)).FirstOrDefault();
        if (person != null)
            _People.Remove(person);
        else
            throw new Exception("Not Found");
    }


    public List<Person> People()
    {
        return _People;
    }
    public List<Person> People(int count)
    {
        return _People.Take(count).ToList();
    }

    public List<Person> Test()
    {
        return _People.ToList();
    }

}

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or code snippets about the feature request here.

@pamidur
Copy link
Owner

pamidur commented Nov 3, 2022

Hi @timeshift92 , as of now you can only use interface instead of attribute. You can't mark members of attribute with aspects. But this is interesting idea! We'll see how we can implement that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants