1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using Autofac;
- using Autofac.Integration.WebApi;
- using Central.Control.WebApi.Service.Interface;
- using IoC;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Web;
- using System.Web.Http;
- using IContainer = Autofac.IContainer;
- namespace Central.Control.WebApi.IOC
- {
-
-
-
- public class IOCService
- {
- private static IContainer _container;
-
-
-
- public static void InitAutofac()
- {
- #region AutoFac IOC容器
- var builder = new ContainerBuilder();
- try
- {
-
-
- builder.RegisterApiControllers(Assembly.GetCallingAssembly());
-
- #region Service
- var assemblysServices = Assembly.Load("Central.Control.WebApi");
- builder.RegisterAssemblyTypes(assemblysServices).AsImplementedInterfaces().InstancePerDependency();
- #endregion
- #region Repository
-
-
- #endregion
-
-
-
-
- _container = builder.Build();
-
-
-
- GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(_container);
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message + "\n" + ex.InnerException);
- }
- #endregion
- }
-
-
-
-
-
- public static T GetFromFac<T>()
- {
- return _container.Resolve<T>();
- }
- }
- }
|