Click here to Skip to main content
15,904,024 members
Home / Discussions / C#
   

C#

 
AnswerRe: Magic Button Text Padding Pin
BillWoodruff15-Jan-12 16:07
professionalBillWoodruff15-Jan-12 16:07 
QuestionSuggestion to do a multilanguage project Pin
Arunkumar.Koloth15-Jan-12 1:21
Arunkumar.Koloth15-Jan-12 1:21 
AnswerRe: Suggestion to do a multilanguage project Pin
venomation15-Jan-12 1:42
venomation15-Jan-12 1:42 
AnswerRe: Suggestion to do a multilanguage project Pin
Not Active15-Jan-12 7:22
mentorNot Active15-Jan-12 7:22 
AnswerRe: Suggestion to do a multilanguage project Pin
Bernhard Hiller15-Jan-12 21:31
Bernhard Hiller15-Jan-12 21:31 
GeneralRe: Suggestion to do a multilanguage project Pin
joost.versteegen16-Jan-12 4:26
joost.versteegen16-Jan-12 4:26 
AnswerRe: Suggestion to do a multilanguage project Pin
jschell16-Jan-12 8:52
jschell16-Jan-12 8:52 
QuestionProblem with Ninject Pin
venomation15-Jan-12 0:28
venomation15-Jan-12 0:28 
I have the following code:
C#
IKernel kernal = new StandardKernel();

kernal.Bind<ILocationComponent>().To<LocationCom>();
kernal.Bind<IComponent>().To<LocationCom>();
kernal.Bind<IComponent>().To<MovementnCom>();


package = kernal.Get<ComponentPackage>();
package.Get<MovementnCom>().Force = new Vector2(10,10);
package.Get<LocationCom>().Position = new Vector2(2,2);


LocationCom:
C#
[Family("Location")]
class LocationCom : BaseComponent, ILocationComponent
{
    public Vector2 Position { get; set; }
}


MovementCom:
C#
[Family("Movement")]
class MovementCom : BaseComponent, IRealtimeComponent
{
    private readonly ILocationComponent locationCom;
    public Vector2 Force { get; set; }

    [Inject]
    public MovementCom(ILocationComponent locationCom)
    {
        this.locationCom = locationCom;
    }

    public void Update(GameTime gameTime)
    {
        locationCom.Position += Force * (float)gameTime.ElapsedGameTime.TotalSeconds;
    }
}


ComponentPackage:
C#
public ComponentPackage(IEnumerable<IComponent> components)
{
    foreach (var component in components)
    {
        Add(component);
    }
}


The idea is that the movement component will get a reference to location component when injected
into the package.

The problem is that MovementCom receives a new instance of LocationCom, thus when it applies
force it is applying it to an unrelated position (not inside the package).

Does Ninject resolve this issue or would I have to write some "adaptor" code for the dependencies to work, I am fairly new to using an IOC container so it is likely to be an easy question Poke tongue | ;-P
AnswerRe: Problem with Ninject Pin
Dave Kreskowiak15-Jan-12 3:23
mveDave Kreskowiak15-Jan-12 3:23 
QuestionRemote PC diagnostics Code Pin
Mohammed NAeem14-Jan-12 21:49
Mohammed NAeem14-Jan-12 21:49 
AnswerRe: Remote PC diagnostics Code Pin
Eddy Vluggen15-Jan-12 6:02
professionalEddy Vluggen15-Jan-12 6:02 
QuestionLooking for help deciphering this code class Pin
turbosupramk313-Jan-12 19:09
turbosupramk313-Jan-12 19:09 
AnswerRe: Looking for help deciphering this code class Pin
Richard MacCutchan13-Jan-12 22:23
mveRichard MacCutchan13-Jan-12 22:23 
GeneralRe: Looking for help deciphering this code class Pin
turbosupramk314-Jan-12 3:28
turbosupramk314-Jan-12 3:28 
GeneralRe: Looking for help deciphering this code class Pin
Richard MacCutchan14-Jan-12 3:41
mveRichard MacCutchan14-Jan-12 3:41 
GeneralRe: Looking for help deciphering this code class Pin
harold aptroot14-Jan-12 4:34
harold aptroot14-Jan-12 4:34 
AnswerRe: Looking for help deciphering this code class Pin
OriginalGriff14-Jan-12 0:23
mveOriginalGriff14-Jan-12 0:23 
GeneralRe: Looking for help deciphering this code class Pin
turbosupramk314-Jan-12 3:27
turbosupramk314-Jan-12 3:27 
GeneralRe: Looking for help deciphering this code class Pin
OriginalGriff14-Jan-12 3:37
mveOriginalGriff14-Jan-12 3:37 
GeneralRe: Looking for help deciphering this code class Pin
turbosupramk314-Jan-12 3:41
turbosupramk314-Jan-12 3:41 
GeneralRe: Looking for help deciphering this code class Pin
OriginalGriff14-Jan-12 3:53
mveOriginalGriff14-Jan-12 3:53 
GeneralRe: Looking for help deciphering this code class Pin
harold aptroot14-Jan-12 4:47
harold aptroot14-Jan-12 4:47 
GeneralRe: Looking for help deciphering this code class Pin
OriginalGriff14-Jan-12 5:03
mveOriginalGriff14-Jan-12 5:03 
GeneralRe: Looking for help deciphering this code class Pin
harold aptroot14-Jan-12 5:22
harold aptroot14-Jan-12 5:22 
GeneralRe: Looking for help deciphering this code class Pin
OriginalGriff14-Jan-12 5:31
mveOriginalGriff14-Jan-12 5:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.