C# - Pass In An Object When Using An IoC Container?

Mar 8, 2011

I am doing a project in ASP.NET MVC in which I want to implement an IoC container. I am new to IoC containers and have been searching to find a solution to my problem, but so far to no avail.

The problem is dat data is distributed across various databases. Once a user is logged in, the database for the user is retrieved from an authorization database and then set in the user session. That user session is passed on to the services and repositories when they are constructed, so they can use it when they need it to access the database.

A typical bare stripped service (without interfaces and ioc) looks like this:

private CompetitionRepository _CompetitionRepo;
public CompetitionService(DataContext dataContext)
: this (new CompetitionRepository(dataContext))
{ }

[code]...

The "DataContext" contains a couple of properties with which the correct database is selected for the session. Because the Services and Repositories don't have access to the session itself (which is outside of their scope) they need this object.

View 1 Replies


Similar Messages:

How To Pass Unit Of Work Container Into Constructor Of Repository Using Dependency Injection

Jul 23, 2010

how to complete my implementation of the Repository pattern in an ASP.NET web application.

At the moment, I have a repository interface per domain class defining methods for e.g. loading and saving instances of that class.

Each repository interface is implemented by a class which does the NHibernate stuff. Castle Windsor sorts out the DI of the class into the interface according to web.config. An example of an implemented class is provided below:

[code].....

As pointed out in a previous thread, the repository class needs to accept an unit of work container (i.e. ISession) rather than instantiating it in every method.

I anticipate that the unit of work container will be created by each aspx page when needed (for example, in a property).

How do I then specify that this unit of work container instance is to be passed into the constructor of StoredWillRepository when Windsor is creating it for me?

View 4 Replies

MVC :: How To Pass JSON Object As Dictionary Object

Oct 23, 2010

In MVC3 Beta version i have action result same like

public ActionResult Save(Dictionary<string, string> dicObject)

I want to pass JSON Object in POST Method from javascript and need to get as dictionary object

How can i do this? can you write example if possible?

View 5 Replies

Pass Data Between Forms - Error "Object Reference Not Set To An Instance Of An Object"

Mar 3, 2010

i am trying to pass data between forms.

Public selected_Month As String
Public Property Month() As String
Get
Return selected_Month
End Get
Set(ByVal value As String)
selected_Month = value
End Set
End Property

form1: where i am assigning a value

Dim my_Class As New Class1
my_Class.Month = ddl_Month.Text.ToString()
form2: where i am geting a value
Dim my_Class2 As New Class1
MessageBox.Show(my_Class2.Month.ToString())

when i run this code, i am getting error like Object reference not set to an instance of an object.

View 6 Replies

C# - Can Pass A .net Object Via Querystring

Jan 25, 2011

I stucked at a condition , where i need to share values between the pages. I want to share value from Codebehind via little or no javascript. I already have a question here on SO , but using JS. Still did'nt got any result so another approach i am asking.

So I want to know can i pass any .net object in query string. SO that i can unbox it on other end conveniently.

Update

Or is there any JavaScript approach, by passing it to windows modal dialog. or something like that.

What I am doing

What i was doing is that on my parent page load. I am extracting the properties from my class that has values fetched from db. and put it in a Session["mySession"]. Some thing like this.

Session["mySession"] = myClass.myStatus which is List<int>;

Now on one my event that checkbox click event from client side, i am opening a popup. and on its page load, extracting the list and filling the checkbox list on the child page.

Now from here user can modify its selection and close this page. Close is done via a button called save , on which i am iterating through the checked items and again sending it in Session["mySession"].

But the problem is here , when ever i again click on radio button to view the updated values , it displays the previous one. That is , If my total count of list is 3 from the db, and after modification it is 1. After reopening it still displays 3 instead of 1.

View 5 Replies

How To Pass Value Object Class Dynamically

Jul 14, 2010

i have 10 classes and i want to send the class in a paramenter dynamically to call a method for example int addmember(aslogic.base obj) smilary i want to pass class in the parameter.

View 4 Replies

WCF / ASMX :: How To Pass Object To Web Service

Nov 4, 2010

I'd like to pass an object (Digital Persona featureset) to a web service. Can't seem to find a good way to serialize it.

View 4 Replies

MVC :: Pass Object From Action To View

Jan 20, 2011

I have the following action executed when a user selects an item from the dropdown;

[Code]....

The object paymentApplicationRefund is populated. I want to get the contents of this object to put in a Html.Textbox(). How do I proceed??

View 11 Replies

MVC :: Aggregate Object Pass As A Hidden Value?

Sep 16, 2010

How to use Html.Hidden for aggregate object?
For Example, I have Model1 which aggregates Model2.

Model:
class Model1
{..
public Model2 model2;
..
}
class Model2

[Code]....

View 2 Replies

Allow Client Pass My Object Through Webservice?

Nov 12, 2010

I want to write a webservice, and in one of its methods, I want user to pass one my object's instance as parameter. It will greatly reduces number of parameters, and help user call this method more effectively. I create some class, but when distributing them to client, only class name remains, all properties and methods are gone, just like this

public class CameraPackages
{
private readonly List<CameraPackage> _packages;
public CameraPackages()
{
_packages = new List<CameraPackage>();
}
public void AddNewCamera(CameraPackage package)
{
_packages.Add(package);
}
public void RemoveCamera(CameraPackage package)
{
if(_packages.Contains(package))
_packages.Remove(package);
else
throw new ArgumentException();
}
}
into this: (in Reference.cs)
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class CameraPackages {
}

How can I do to allow user use my object?

View 1 Replies

MVC :: Pass Javascript Object Value To Controller?

Feb 9, 2010

Consider the following data

<xml>
<id>10</id>
<value1>15<value1>
</xml>

I need to use this data as an input to ajax request. For eg. consider a dropdownlist change event, I need to pass these values to the controller.

sample code

//dropdown change event
$("#TestReqID").change(function() {
var id = 10;
var testResults = "abc";
var inXML = "<xml>";
inXML = inXML + "<id>" + id + "</id>";
inXML = inXML + "<value1>" + testResults + "</value1>";
inXML = inXML + "</xml>"
$.getJSON("/Home/UpdateTest/Json/" + inXML, function(data) {
//success code goes here
});
});

in HomeController

public ActionResult UpdateTest(string obj)
{
if (HttpContext.Request.IsAjaxRequest())
{
/*
Need to parse data in "obj" from ajax request
*/
IPTests test = _service.GetIPTest(Convert.ToInt32(id));
return new JsonResult { Data = new { ipTestId = "0", testResults = "" } };
}
return View(test);
}

instead of xml string is it possible to use javascript object like

[Code]....

View 2 Replies

C# - Pass Object From Webserver To Client?

Jun 9, 2010

I developed a C# web application that calls a web-service which returns a base64 encoded array (PDF file). I then convert that array into a UCOMIStream object (I know it is obsolete, but the DLL that I am using requires it as a parameter). I use the following code to do the conversion which works perfectly. I can pass this object to the DLL so that I can print the PDF.

This works great on the Webserver, but the requirement is to print it locally.

Byte[] bBuffer = statementOut.statementcycle.statementdata.content;
int size = bBuffer.Length;
IntPtr mem = Marshal.AllocHGlobal(size);
Marshal.Copy(bBuffer, 0, mem, size);
// Create an OLE Stream object.
System.Runtime.InteropServices.UCOMIStream str; //obsolete but the createstreamonhglobal outputs it
CreateStreamOnHGlobal(mem, true, out str);

The DLL resides on the client so I am able to use ActiveX to create the object using javascript and/or VBscript;however, I have not been able to figure out how to get the stream object to the client to pass to the DLL.

View 2 Replies

Pass A Sql Connection Object By Reference?

Mar 7, 2011

using vb.net/asp.net 2005.

I am trying to pass a sql connection object by reference ("ByRef") like so but when I'm inside the function that i'm passing it to it sees the connection as closed, what am i doing wrong?

[Code]....

View 1 Replies

Can Pass An Object Between Separated Applications By Web Service

Dec 26, 2010

I have a web service Writed By VB.net Lang return a DataSet Contain many rows , I tried to Call this Web Service From Java applicationput Java Language cant Deal with dataSet , So I need to Convert the Dataset to an Object

<WebMethod()> _
Public Function GetLogBook(ByVal EmployeeNumber As String, _
ByVal EmployeeName As String) As DataSet
Dim ds As New DataSet
Dim conn As New
[code]...

View 3 Replies

WCF / ASMX :: Can Pass Object In Rest Service Uri

Jan 18, 2011

can Pass object in Rest Service Uri

View 1 Replies

How To Pass 'user' Object From Aspx To Silverlight 4

Dec 28, 2010

First, we are constrained to using an existing web framework that handles authentication and authorization. The web project uses forms authentication and writes to an encrypted cookie. The user information is exposed to the aspx pages as a property:

LoggedInUser.Current

This has several properties including the userId and role list.

I've looked at using initParams, but haven't been very successful there (edit: I couldn't do it dynamically originally). I've created a simple POCO entity with a [Key] attribute, but I need to at least be able to pass the userId from the aspx page to the imbedded silverlight.

What is the easiest way to pass a dynamic object from aspx to silverlight 4?

[Code]....

Then used Slugster's example to use the values on the Silverlight side.

Warning: Passing user information via init params exposes the info as plain text to the user viewing the page (they just have to view the source). We ended up using an authentication domain service and using the same user object as the aspx

View 2 Replies

DataSource Controls :: Pass Object As SessionParameter In ObjectDataSource?

Dec 28, 2010

Is it possible to pass a domain object as session parameter in an ObjectDataSource. I'm doing this:

<asp:ObjectDataSource ID="ParticipantsDataSource" runat="server" OnInit="SqlDataSource_Load"
SelectMethod="LoadParticipants" TypeName="SB.Web.units.Players">
<SelectParameters>
<asp:SessionParameter Name="user" SessionField="User" Type="SB.BusinessLogic.DomainEntity.User" />
</SelectParameters>
</asp:ObjectDataSource>

But I get the error message that I can't create an object of the type System.TypeCode from the string containing SB.BusinessLogic.DomainEntity.User for the property Type.

View 1 Replies

Security :: Pass Membership Identity Object Across Domain?

Aug 20, 2010

I am trying to figure a way to SSO with ASP.NET membership and role model.

I can implement custom membership provider which consume web services hosting on a server.

With encryption of data. No problem.

But my question is, If I sign on a website with my provider, got my identity object on that application,

could I pass it to another website on another domain which use the same provider and by doing so, do not need to login again?

View 2 Replies

Pass Key Of Grid To Business Class Via Object Data Source?

Sep 15, 2010

In ASP.NET Webforms have an ASP.NET GridView connected to a C# class via an object data source

I have an ID set up as a DataKeyName in the grid. How do I pass this to the C# class when I update the grid?

View 15 Replies

Pass Key Of Grid To Business Class Via Object Data Source

Jan 21, 2011

In ASP.NET Webforms have an ASP.NET GridView connected to a C# class via an object data source

I have an ID set up as a DataKeyName in the grid. How do I pass this to the C# class when I update the grid?

View 2 Replies

C# - How To Pass The Data Path For Object Flash Tag From The Root Directory

Sep 21, 2010

I'm using urlrewriting to rewrite my url. Let me introduce my problem by bellow example: Here is old url: http://localhost/test/pages.aspx?pageid=1 I have 2 cases to rewrite:

http://localhost/test/url-rewriting-get-start.aspx
http://localhost/test/url-rewriting/get-start.aspx

The first case is ok, but I would like to use the second case. In this case I must use root path for image, css and object tag (for flash):

With image, I modified to: <image src="~/images/icon.jpg" runat="server"/>
With css, I modified in head tag: <head runat="server">

But with the object tag, I don't know how to set root for the data, movie parameter:

<object data="anim/head.swf?xmlPath=./menu_flash.html" type="application/x-shockwave-flash" width="962" height="228">
<param name="movie" value="anim/head.swf" />
<param name="quality" value="high" />

View 2 Replies

DataSource Controls :: How To Pass An Object To The Selectmethod Of The Objectdatasource Control

Mar 31, 2011

how to pass an object to the selectmethod of the objectdatasource control?

View 2 Replies

How To Pass Binary Value To Active Socket Object 3.5 - Dll Function WriteAsUnicode

Aug 5, 2010

I am using one DLL file of Active Socket Object 3.5 and it has one function writeAsUnicode which take String as parameter. But I need to pass binary value. In ASP, it can be done but in asp.net it becomes problem. So is there any other way to solve it.

View 1 Replies

Javascript - How To Pass Json Collection Object To Mvc Controller Action Method

Dec 21, 2010

I am creating one Json array object and trying to pass it in MVC controller action method but i am getting null paramerter; as per my knowledge json only maps .net primitive datatypes.... so it assign null value.

Note: when i have look at request object i found that there are three parameter of created array. But how to get that value as parameter of function?

View 2 Replies

Security :: Calling Users NetworkCredential Object From The WCF Service And Pass It To The OCS Call?

Aug 27, 2010

I have the following scenario. An user uses the desktop application to call our WCF Service which has windows authentication. The WCF Service calls the Office Communication Server (OCS) in order to do some custom work.

When the WCF Service calls OCS we have to pass an instance of NetWorkCredential into the call. I want to pass in the original calling users NetworkCredential object into the OCS call rather than constructing it using a custom username and password. How do I get access to the calling users NetworkCredential object from the WCF service and pass it to the OCS call?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved