0

私が見たいくつかの設計にほぼ従って、各ビジネスオブジェクトにリポジトリとサービスが関連付けられているASP.NETアプリケーションを構築しています。リポジトリはnHibernateのISessionを使用してCRUD操作を実行し、対応するサービスはリポジトリメンバーにアクセスします。

ASP.NETでObjectDataSourceを使用する場合、サービスではなくリポジトリに直接バインドすることは悪い習慣と見なされますか(したがって、サービスレイヤーを完全にスキップします)?または、単純なCRUD操作を実行するだけの場合、サービスレイヤーは実際には必要ありませんか?

// Repository interface
public partial interface IRepository<T>
{
    void Add(T entity);
    void Update(T entity);
    void Remove(T entity);
    ICollection<T> GetAll();
    T GetByKey(int _ID);
}

// Service example
public class TestService : IService<Test>
{
    private static TestRepository _repository;
    ...

    public virtual ICollection<Test> FindAll()
    {
        return (_repository.GetAll());
    }

    public virtual Test FindBy(int Id)
    {
        return (_repository.GetByKey(Id));
    }

    public virtual void Save(Test entity)
    {
        _repository.Update(entity);
    }

    public virtual void Add(Test entity)
    {
        _repository.Add(entity);
    }

    public virtual void Remove(Test entity)
    {
        _repository.Remove(entity);
    }
}
4

1 に答える 1

0

Definitely your UI shouldn't know about the data access. Even though you are not manipulating the data coming from the database, it is a good practice to have at least one more layer(Service, or Business Layer) and let your UI interact with the service. If I were you, I would do a poorman MVC for the Asp.net so that I can unit test

于 2013-01-25T00:03:50.327 に答える