Skip to content

Unityconfig container

Peter Dzuya

Asked May 30, 2016, 2:02 AM EDT1 answer
Share
LinkedInX
Hi All,
 
I want bind data as shown here in below.
 
TypeScript
        private readonly IStockItemService _stockItemService;
        private readonly StockItem _stockItem;
        public frmStockItenListing() {
            InitializeComponent();
            _stockItemService = UnityConfig.GetContainer().Resolve<IStockItemService>();
        }

        private void barButtonClose_ItemClick(object sender, ItemClickEventArgs e) {
            if (MessageBox.Show("Are you sure", "GMIS - Close", MessageBoxButtons.YesNo, MessageBoxIcon.Information) ==
  DialogResult.Yes) {
                this.Close();
            }
        }

        private void frmStockItenListing_Load(object sender, EventArgs e)
        {

            stockItemBindingSource.DataSource = _stockItemService.GetAll();
        }
    }
 
My Interface is as follows
 
 
C#
namespace MakGarm.Business.Contracts {
        public interface IStockItemService {
            void Insert(StockItem entity);

            void Update(StockItem entity);

        StockItem GetById(int entityId);

            void Delete(int entityId);

            IEnumerable<StockItem> GetAll();

        IEnumerable<StockItem> GetByContactId(int contactId);

        IEnumerable<StockItem> GetByProcessedJobCardsId(int contactId);
    }
    }
I get the following runtime error after launching my project and upon hitting the button that runs this process.
 
 
 
I don't know where I went wrong.  Please assist.
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I added the following Code to My "UnityConfig" file.
    container.RegisterType<IStockItemRepository, StockItemRepository>(new PerResolveLifetimeManager());
    container.RegisterType<IStockItemService, StockItemService>(new PerResolveLifetimeManager());
    And my run time error was solved.
    Thanks
    0