using System;
using System.Linq;
using System.Reflection;

using Autofac;

namespace XHD.Core.View.Configs
{
    /// <summary>
    /// 注入仓储接口
    /// </summary>
    public class RepositoryModule:Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            //反射程序集方式服务注册
            Assembly repository = Assembly.Load("XHD.Core.Repository");
            Assembly irepository = Assembly.Load("XHD.Core.IRepository");
            builder.RegisterAssemblyTypes(repository, irepository)
            .Where(t => t.FullName.EndsWith("Repository") && !t.IsAbstract) //类名以service结尾，且类型不能是抽象的　
                .InstancePerLifetimeScope() //作用域生命周期
                .AsImplementedInterfaces()
                .PropertiesAutowired(); //属性注入
        }
    }
}
